From 2c4237dbf094b04b5ebb34418cbec18ad1826053 Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Tue, 25 Aug 2009 00:29:07 -0700 Subject: Add sample code for writing a pre-boot system update hook. Change-Id: I6021d966c2a842ce0e3e4688e2f5f56f01841c7b --- apps/upgrade/Android.mk | 31 ++++++++++++++ apps/upgrade/AndroidManifest.xml | 32 +++++++++++++++ .../example/android/platform/upgrade/Upgrade.java | 48 ++++++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 apps/upgrade/Android.mk create mode 100644 apps/upgrade/AndroidManifest.xml create mode 100644 apps/upgrade/src/com/example/android/platform/upgrade/Upgrade.java 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 @@ + + + + + + + + + + + + + + + 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); + } +} + -- cgit v1.2.3