summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2013-03-11 17:48:43 -0700
committerDianne Hackborn <hackbod@google.com>2013-03-12 12:51:38 -0700
commitc895be7bc68b6f5b37fbb9881f464dd5ea0eb017 (patch)
treefe7ba171c41d3df63b595adaf46a67ace2a7d7d3 /tests
parent9725d80adc7426ea20f3a193fc81dc1e8b8c4b31 (diff)
downloadframeworks_base-c895be7bc68b6f5b37fbb9881f464dd5ea0eb017.zip
frameworks_base-c895be7bc68b6f5b37fbb9881f464dd5ea0eb017.tar.gz
frameworks_base-c895be7bc68b6f5b37fbb9881f464dd5ea0eb017.tar.bz2
Implement limited shared libraries in apks.
You can now declare shared libraries in apks that are on the system image. This is like the existing mechanism of using raw jar files as shared libraries, but since they are contained in an apk the library can actually be updated from the Play Store. And this even (mostly) works. There are some deliberate limitations on this feature. A new shared library *must* be declared by an apk on the system image. Installing an update to a system image apk does not allow you to add new shared libraries; they must be defined by everything on the base system image. This allows us to get rid of a lot of ugly edge cases (shared libraries that were there disappearing after an update is uninstalled for example) and give some brakes on apps that happen to be pre-installed on devices from being able to throw in new shared libraries after the fact. In working on this, I ran into a recently introduced bug where uninstalling updated to system apps would fail. This was done to allow for the new restricted users that don't have all system apps, but conflicts with the existing semantics for uninstalling system apps. To fix this I added a new uninstall flag that lets you switch on the new mode if desired. Also to implement the desired logic for limitations on declaring new shared libraries in app updates, I needed to slightly tweak the initial boot to keep the Package object for hidden system packages associated with their PackageSetting, so we can look at it to determine which shared libraries are allowed. I think this is probably more right than it was before -- we already need to parse the package anyway, so we have it, and when you install an update to a system app we are in this same state until you reboot anyway. And having this fixed also allowed me to fix another bug where we wouldn't grant a new permission to an updated app if its system image version is updated to request the permission but its version is still older than whatever is currently installed as an update. So that's good. Also add new sample code showing the implementation of an apk shared library and a client app using it. Change-Id: I8ccca8f3c3bffd036c5968e22bd7f8a73e69be22
Diffstat (limited to 'tests')
-rw-r--r--tests/SharedLibrary/client/Android.mk12
-rw-r--r--tests/SharedLibrary/client/AndroidManifest.xml29
-rw-r--r--tests/SharedLibrary/client/res/values/strings.xml19
-rw-r--r--tests/SharedLibrary/client/src/com/google/android/test/lib_client/ActivityMain.java35
-rw-r--r--tests/SharedLibrary/lib/Android.mk10
-rw-r--r--tests/SharedLibrary/lib/AndroidManifest.xml29
-rw-r--r--tests/SharedLibrary/lib/res/values/strings.xml22
-rw-r--r--tests/SharedLibrary/lib/src/com/google/android/test/shared_library/ActivityMain.java32
-rw-r--r--tests/SharedLibrary/lib/src/com/google/android/test/shared_library/SharedLibraryMain.java87
9 files changed, 275 insertions, 0 deletions
diff --git a/tests/SharedLibrary/client/Android.mk b/tests/SharedLibrary/client/Android.mk
new file mode 100644
index 0000000..60ef92a
--- /dev/null
+++ b/tests/SharedLibrary/client/Android.mk
@@ -0,0 +1,12 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-subdir-java-files)
+
+LOCAL_APK_LIBRARIES := SharedLibrary
+
+LOCAL_PACKAGE_NAME := SharedLibraryClient
+
+LOCAL_MODULE_TAGS := tests
+
+include $(BUILD_PACKAGE)
diff --git a/tests/SharedLibrary/client/AndroidManifest.xml b/tests/SharedLibrary/client/AndroidManifest.xml
new file mode 100644
index 0000000..c6a43c0
--- /dev/null
+++ b/tests/SharedLibrary/client/AndroidManifest.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2013 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.google.android.test.lib_client">
+ <application android:label="@string/app_title">
+ <uses-library android:name="android.test.runner" />
+ <uses-library android:name="com.google.android.test.shared_library" />
+ <activity android:name="ActivityMain">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+</manifest>
diff --git a/tests/SharedLibrary/client/res/values/strings.xml b/tests/SharedLibrary/client/res/values/strings.xml
new file mode 100644
index 0000000..3757a25
--- /dev/null
+++ b/tests/SharedLibrary/client/res/values/strings.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2013 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="app_title">SharedLibrary client</string>
+</resources>
diff --git a/tests/SharedLibrary/client/src/com/google/android/test/lib_client/ActivityMain.java b/tests/SharedLibrary/client/src/com/google/android/test/lib_client/ActivityMain.java
new file mode 100644
index 0000000..d6121a5
--- /dev/null
+++ b/tests/SharedLibrary/client/src/com/google/android/test/lib_client/ActivityMain.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2013 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 com.google.android.test.lib_client;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.widget.TextView;
+import com.google.android.test.shared_library.SharedLibraryMain;
+
+public class ActivityMain extends Activity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ TextView content = new TextView(this);
+ content.setText("Library version: " + SharedLibraryMain.getVersion(this) + "!");
+
+ SharedLibraryMain.ensureVersion(this, SharedLibraryMain.VERSION_BASE);
+ setContentView(content);
+ }
+}
diff --git a/tests/SharedLibrary/lib/Android.mk b/tests/SharedLibrary/lib/Android.mk
new file mode 100644
index 0000000..c19e23a
--- /dev/null
+++ b/tests/SharedLibrary/lib/Android.mk
@@ -0,0 +1,10 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-subdir-java-files)
+
+LOCAL_PACKAGE_NAME := SharedLibrary
+
+LOCAL_MODULE_TAGS := tests
+
+include $(BUILD_PACKAGE)
diff --git a/tests/SharedLibrary/lib/AndroidManifest.xml b/tests/SharedLibrary/lib/AndroidManifest.xml
new file mode 100644
index 0000000..31fac20
--- /dev/null
+++ b/tests/SharedLibrary/lib/AndroidManifest.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2013 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.google.android.test.shared_library"
+ android:versionCode="2">
+ <application android:label="SharedLibrary">
+ <library android:name="com.google.android.test.shared_library" />
+ <activity android:name="ActivityMain">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+</manifest>
diff --git a/tests/SharedLibrary/lib/res/values/strings.xml b/tests/SharedLibrary/lib/res/values/strings.xml
new file mode 100644
index 0000000..bbfb0b4
--- /dev/null
+++ b/tests/SharedLibrary/lib/res/values/strings.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2013 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 xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="upgrade_title">Upgrade required</string>
+ <string name="upgrade_body"><xliff:g id="app">%1$s</xliff:g> requires a newer version
+ of <xliff:g id="lib">%2$s</xliff:g> to run.</string>
+ <string name="upgrade_button">Upgrade</string>
+</resources>
diff --git a/tests/SharedLibrary/lib/src/com/google/android/test/shared_library/ActivityMain.java b/tests/SharedLibrary/lib/src/com/google/android/test/shared_library/ActivityMain.java
new file mode 100644
index 0000000..895aced
--- /dev/null
+++ b/tests/SharedLibrary/lib/src/com/google/android/test/shared_library/ActivityMain.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2013 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 com.google.android.test.shared_library;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.widget.TextView;
+
+public class ActivityMain extends Activity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ TextView content = new TextView(this);
+ content.setText("Dummy main entry for this apk; not really needed...");
+ setContentView(content);
+ }
+}
diff --git a/tests/SharedLibrary/lib/src/com/google/android/test/shared_library/SharedLibraryMain.java b/tests/SharedLibrary/lib/src/com/google/android/test/shared_library/SharedLibraryMain.java
new file mode 100644
index 0000000..c1cd925
--- /dev/null
+++ b/tests/SharedLibrary/lib/src/com/google/android/test/shared_library/SharedLibraryMain.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2013 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 com.google.android.test.shared_library;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.res.Resources;
+
+public class SharedLibraryMain {
+ private static String LIBRARY_PACKAGE = "com.google.android.test.shared_library";
+
+ /**
+ * Base version of the library.
+ */
+ public static int VERSION_BASE = 1;
+
+ /**
+ * The second version of the library.
+ */
+ public static int VERSION_SECOND = 2;
+
+ public static int getVersion(Context context) {
+ PackageInfo pi = null;
+ try {
+ pi = context.getPackageManager().getPackageInfo(LIBRARY_PACKAGE, 0);
+ return pi.versionCode;
+ } catch (PackageManager.NameNotFoundException e) {
+ throw new IllegalStateException("Can't find my package!", e);
+ }
+ }
+
+ public static void ensureVersion(Activity activity, int minVersion) {
+ if (getVersion(activity) >= minVersion) {
+ return;
+ }
+
+ // The current version of the library does not meet the required version. Show
+ // a dialog to inform the user and have them update to the current version.
+ // Note that updating the library will be necessity mean killing the current
+ // application (so it can be re-started with the new version, so there is no
+ // reason to return a result here.
+ final Context context;
+ try {
+ context = activity.createPackageContext(LIBRARY_PACKAGE, 0);
+ } catch (PackageManager.NameNotFoundException e) {
+ throw new IllegalStateException("Can't find my package!", e);
+ }
+
+ // Display the dialog. Note that we don't need to deal with activity lifecycle
+ // stuff because if the activity gets recreated, it will first call through to
+ // ensureVersion(), causing us to either re-display the dialog if needed or let
+ // it now proceed.
+ final Resources res = context.getResources();
+ AlertDialog.Builder builder = new AlertDialog.Builder(activity);
+ builder.setTitle(res.getText(R.string.upgrade_title));
+ builder.setMessage(res.getString(R.string.upgrade_body,
+ activity.getApplicationInfo().loadLabel(activity.getPackageManager()),
+ context.getApplicationInfo().loadLabel(context.getPackageManager())));
+ builder.setPositiveButton(res.getText(R.string.upgrade_button),
+ new Dialog.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ // Launch play store.
+ }
+ });
+ builder.show();
+ }
+}