aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSvet Ganov <svetoslavganov@google.com>2016-01-20 09:37:32 -0800
committerSvetoslav Ganov <svetoslavganov@google.com>2016-02-08 23:21:43 +0000
commit61e73383ede2c8de0dd2465f979a01bb43d8d064 (patch)
treef80677c66801218f7add0588ff29e627459d506d
parentc9935b475f131cde1c79c10126eae90992fbb6a0 (diff)
downloadexperimental-61e73383ede2c8de0dd2465f979a01bb43d8d064.tar.gz
Multi packages per APK sample
This is a sample that shows how to declare multi packages per APK. The feature is currently supported only for privileged apps or updates to such apps. The sample declares three activities wihch on old platforms are in the parent package but on devices running API 24 two of the activities are disabled in the parent and moved to the first and second child packages respectively. Change-Id: I673d9c455b3c8543091e83e8d37e35c4af1067d7
-rw-r--r--MultiPackageApk/Android.mk13
-rw-r--r--MultiPackageApk/AndroidManifest.xml122
-rw-r--r--MultiPackageApk/res/drawable-hdpi/ic_launcher.pngbin0 -> 3014 bytes
-rw-r--r--MultiPackageApk/res/drawable-ldpi/ic_launcher.pngbin0 -> 1504 bytes
-rw-r--r--MultiPackageApk/res/drawable-mdpi/ic_launcher.pngbin0 -> 1969 bytes
-rw-r--r--MultiPackageApk/res/drawable-xhdpi/ic_launcher.pngbin0 -> 4006 bytes
-rw-r--r--MultiPackageApk/res/layout/my_activity.xml32
-rw-r--r--MultiPackageApk/res/values-v24/consts.xml20
-rw-r--r--MultiPackageApk/res/values/consts.xml20
-rw-r--r--MultiPackageApk/res/values/strings.xml26
-rw-r--r--MultiPackageApk/src/foo/bar/multi/FirstActivity.java21
-rw-r--r--MultiPackageApk/src/foo/bar/multi/MyActivity.java48
-rw-r--r--MultiPackageApk/src/foo/bar/multi/SecondActivity.java21
-rw-r--r--MultiPackageApk/src/foo/bar/multi/ThirdActivity.java21
14 files changed, 344 insertions, 0 deletions
diff --git a/MultiPackageApk/Android.mk b/MultiPackageApk/Android.mk
new file mode 100644
index 0000000..91a1f5b
--- /dev/null
+++ b/MultiPackageApk/Android.mk
@@ -0,0 +1,13 @@
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := MultiPackageApk
+
+LOCAL_PRIVILEGED_MODULE := true
+
+include $(BUILD_PACKAGE)
diff --git a/MultiPackageApk/AndroidManifest.xml b/MultiPackageApk/AndroidManifest.xml
new file mode 100644
index 0000000..48116e2
--- /dev/null
+++ b/MultiPackageApk/AndroidManifest.xml
@@ -0,0 +1,122 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+ * Copyright (c) 2016 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="foo.bar.multi.parent"
+ android:versionCode="100"
+ android:versionName="100.0">
+
+ <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="23"/>
+
+ <uses-permission android:name="android.permission.READ_CONTACTS" />
+ <uses-permission android:name="android.permission.READ_CALENDAR" />
+
+ <application
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/parent_name"
+ android:allowBackup="false">
+
+ <!-- Always in foo.bar.multi.parent. -->
+ <activity
+ android:name="foo.bar.multi.FirstActivity"
+ android:label="@string/first_activity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
+ </intent-filter>
+ </activity>
+
+ <!-- In foo.bar.multi.parent up to API 23. From API 24 in foo.bar.multi.child1. -->
+ <activity
+ android:name="foo.bar.multi.SecondActivity"
+ android:label="@string/second_activity"
+ android:enabled="@bool/second_activity_enabled">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
+ </intent-filter>
+ </activity>
+
+ <!-- In foo.bar.multi.parent up to API 23. From API 24 in foo.bar.multi.child2. -->
+ <activity
+ android:name="foo.bar.multi.ThirdActivity"
+ android:label="@string/third_activity"
+ android:enabled="@bool/third_activity_enabled">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
+ </intent-filter>
+ </activity>
+
+ </application>
+
+ <package
+ package="foo.bar.multi.child1">
+
+ <uses-permission android:name="android.permission.READ_CONTACTS" />
+ <uses-permission android:name="android.permission.READ_CALENDAR" />
+
+ <application
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/first_child"
+ android:allowBackup="false">
+
+ <activity
+ android:name="foo.bar.multi.SecondActivity"
+ android:label="@string/second_activity" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
+ </intent-filter>
+ </activity>
+
+ </application>
+
+ </package>
+
+ <package
+ package="foo.bar.multi.child2">
+
+ <uses-permission android:name="android.permission.READ_CONTACTS" />
+ <uses-permission android:name="android.permission.READ_CALENDAR" />
+
+ <application
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/second_child"
+ android:allowBackup="false">
+
+ <activity
+ android:name="foo.bar.multi.ThirdActivity"
+ android:label="@string/third_activity" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
+ </intent-filter>
+ </activity>
+
+ </application>
+
+ </package>
+
+</manifest>
diff --git a/MultiPackageApk/res/drawable-hdpi/ic_launcher.png b/MultiPackageApk/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 0000000..a301d57
--- /dev/null
+++ b/MultiPackageApk/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/MultiPackageApk/res/drawable-ldpi/ic_launcher.png b/MultiPackageApk/res/drawable-ldpi/ic_launcher.png
new file mode 100644
index 0000000..2c2a58b
--- /dev/null
+++ b/MultiPackageApk/res/drawable-ldpi/ic_launcher.png
Binary files differ
diff --git a/MultiPackageApk/res/drawable-mdpi/ic_launcher.png b/MultiPackageApk/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 0000000..f91f736
--- /dev/null
+++ b/MultiPackageApk/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/MultiPackageApk/res/drawable-xhdpi/ic_launcher.png b/MultiPackageApk/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..96095ec
--- /dev/null
+++ b/MultiPackageApk/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/MultiPackageApk/res/layout/my_activity.xml b/MultiPackageApk/res/layout/my_activity.xml
new file mode 100644
index 0000000..88bdcb3
--- /dev/null
+++ b/MultiPackageApk/res/layout/my_activity.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2016 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ tools:context=".MyActivity"
+ android:orientation="vertical" >
+
+ <TextView
+ android:id="@+id/text"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:layout_gravity="center"
+ android:textAppearance="@android:style/TextAppearance.Material.Medium">
+ </TextView>
+
+</LinearLayout>
diff --git a/MultiPackageApk/res/values-v24/consts.xml b/MultiPackageApk/res/values-v24/consts.xml
new file mode 100644
index 0000000..7b31875
--- /dev/null
+++ b/MultiPackageApk/res/values-v24/consts.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2016 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources>
+ <bool name="second_activity_enabled">false</bool>
+ <bool name="third_activity_enabled">false</bool>
+</resources>
diff --git a/MultiPackageApk/res/values/consts.xml b/MultiPackageApk/res/values/consts.xml
new file mode 100644
index 0000000..051c17b
--- /dev/null
+++ b/MultiPackageApk/res/values/consts.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2016 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources>
+ <bool name="second_activity_enabled">true</bool>
+ <bool name="third_activity_enabled">true</bool>
+</resources> \ No newline at end of file
diff --git a/MultiPackageApk/res/values/strings.xml b/MultiPackageApk/res/values/strings.xml
new file mode 100644
index 0000000..7d7ee21
--- /dev/null
+++ b/MultiPackageApk/res/values/strings.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2016 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources>
+
+ <string name="parent_name">Parent</string>
+ <string name="first_child">First child</string>
+ <string name="second_child">Second child</string>
+ <string name="first_activity">First activity</string>
+ <string name="second_activity">Second activity</string>
+ <string name="third_activity">Third activity</string>
+
+</resources>
diff --git a/MultiPackageApk/src/foo/bar/multi/FirstActivity.java b/MultiPackageApk/src/foo/bar/multi/FirstActivity.java
new file mode 100644
index 0000000..14b04c8
--- /dev/null
+++ b/MultiPackageApk/src/foo/bar/multi/FirstActivity.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package foo.bar.multi;
+
+public class FirstActivity extends MyActivity {
+
+}
diff --git a/MultiPackageApk/src/foo/bar/multi/MyActivity.java b/MultiPackageApk/src/foo/bar/multi/MyActivity.java
new file mode 100644
index 0000000..23747f9
--- /dev/null
+++ b/MultiPackageApk/src/foo/bar/multi/MyActivity.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package foo.bar.multi;
+
+import android.app.Activity;
+import android.app.ActivityManager;
+import android.os.Bundle;
+import android.os.Process;
+import android.widget.TextView;
+import foo.bar.multi.parent.R;
+
+import java.util.List;
+
+public class MyActivity extends Activity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.my_activity);
+
+ String processName = null;
+ ActivityManager activityManager = getSystemService(ActivityManager.class);
+ List<ActivityManager.RunningAppProcessInfo> runningProcesses = activityManager.getRunningAppProcesses();
+ for (ActivityManager.RunningAppProcessInfo runningProcess : runningProcesses) {
+ if (runningProcess.uid == Process.myUid()) {
+ processName = runningProcess.processName;
+ break;
+ }
+ }
+
+ TextView title = (TextView) findViewById(foo.bar.multi.parent.R.id.text);
+ title.setText("Process: " + processName);
+ }
+}
diff --git a/MultiPackageApk/src/foo/bar/multi/SecondActivity.java b/MultiPackageApk/src/foo/bar/multi/SecondActivity.java
new file mode 100644
index 0000000..8c67f71
--- /dev/null
+++ b/MultiPackageApk/src/foo/bar/multi/SecondActivity.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package foo.bar.multi;
+
+public class SecondActivity extends MyActivity {
+
+}
diff --git a/MultiPackageApk/src/foo/bar/multi/ThirdActivity.java b/MultiPackageApk/src/foo/bar/multi/ThirdActivity.java
new file mode 100644
index 0000000..75a04aa
--- /dev/null
+++ b/MultiPackageApk/src/foo/bar/multi/ThirdActivity.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package foo.bar.multi;
+
+public class ThirdActivity extends MyActivity {
+
+}