aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2009-08-25 00:29:07 -0700
committerDianne Hackborn <hackbod@google.com>2009-08-25 00:29:07 -0700
commit2c4237dbf094b04b5ebb34418cbec18ad1826053 (patch)
treec0d5ae147ada491901d8c315253cb8b31da4a462
parent5e020c61eb37fe6e84e77e58281a247ac4f7aa65 (diff)
downloadsample-2c4237dbf094b04b5ebb34418cbec18ad1826053.tar.gz
Add sample code for writing a pre-boot system update hook.
Change-Id: I6021d966c2a842ce0e3e4688e2f5f56f01841c7b
-rw-r--r--apps/upgrade/Android.mk31
-rw-r--r--apps/upgrade/AndroidManifest.xml32
-rw-r--r--apps/upgrade/src/com/example/android/platform/upgrade/Upgrade.java48
3 files changed, 111 insertions, 0 deletions
diff --git a/apps/upgrade/Android.mk b/apps/upgrade/Android.mk
new file mode 100644
index 0000000..8217ca3
--- /dev/null
+++ b/apps/upgrade/Android.mk
@@ -0,0 +1,31 @@
+#
+# Copyright (C) 2008 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.
+#
+
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := user
+
+# This is the target being built.
+LOCAL_PACKAGE_NAME := UpgradeExample
+
+# Only compile source java files in this apk.
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+# Link against the current Android SDK.
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_PACKAGE)
diff --git a/apps/upgrade/AndroidManifest.xml b/apps/upgrade/AndroidManifest.xml
new file mode 100644
index 0000000..a3054e0
--- /dev/null
+++ b/apps/upgrade/AndroidManifest.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2008 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.
+-->
+
+<!-- This is an example of writing an application that will can perform
+ additional work after a system update.. -->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.platform.upgrade">
+
+ <application android:label="Upgrade App">
+ <receiver android:name="Upgrade">
+ <!-- This broadcast is sent after the core system has finished
+ booting, before the home app is launched or BOOT_COMPLETED
+ is sent. -->
+ <intent-filter>
+ <action android:name="android.intent.action.PRE_BOOT_COMPLETED"/>
+ </intent-filter>
+ </receiver>
+ </application>
+</manifest>
diff --git a/apps/upgrade/src/com/example/android/platform/upgrade/Upgrade.java b/apps/upgrade/src/com/example/android/platform/upgrade/Upgrade.java
new file mode 100644
index 0000000..a9e04ca
--- /dev/null
+++ b/apps/upgrade/src/com/example/android/platform/upgrade/Upgrade.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2007 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.example.android.platform.upgrade;
+
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.util.Log;
+
+/**
+ * This will be launched during system boot, after the core system has
+ * been brought up but before any non-persistent processes have been
+ * started. It is launched in a special state, with no content provider
+ * or custom application class associated with the process running.
+ */
+public class Upgrade extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ // We are now running with the system up, but no apps started,
+ // so can do whatever cleanup after an upgrade that we want.
+ Log.i("Example", "******************* UPGRADE HERE *******************");
+
+ // And now disable this component so it won't get launched during
+ // the following system boots.
+
+ context.getPackageManager().setComponentEnabledSetting(
+ new ComponentName(context, getClass()),
+ PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
+ PackageManager.DONT_KILL_APP);
+ }
+}
+