summaryrefslogtreecommitdiffstats
path: root/packages/BackupRestoreConfirmation
diff options
context:
space:
mode:
Diffstat (limited to 'packages/BackupRestoreConfirmation')
-rw-r--r--packages/BackupRestoreConfirmation/Android.mk31
-rw-r--r--packages/BackupRestoreConfirmation/AndroidManifest.xml33
-rw-r--r--packages/BackupRestoreConfirmation/res/layout/confirm_backup.xml53
-rw-r--r--packages/BackupRestoreConfirmation/res/layout/confirm_restore.xml53
-rw-r--r--packages/BackupRestoreConfirmation/res/values/strings.xml32
-rw-r--r--packages/BackupRestoreConfirmation/src/com/android/backupconfirm/BackupRestoreConfirmation.java237
6 files changed, 439 insertions, 0 deletions
diff --git a/packages/BackupRestoreConfirmation/Android.mk b/packages/BackupRestoreConfirmation/Android.mk
new file mode 100644
index 0000000..e775b44
--- /dev/null
+++ b/packages/BackupRestoreConfirmation/Android.mk
@@ -0,0 +1,31 @@
+#
+# Copyright (C) 2011 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 := optional
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := BackupRestoreConfirmation
+LOCAL_CERTIFICATE := platform
+
+include $(BUILD_PACKAGE)
+
+########################
+include $(call all-makefiles-under,$(LOCAL_PATH))
+
diff --git a/packages/BackupRestoreConfirmation/AndroidManifest.xml b/packages/BackupRestoreConfirmation/AndroidManifest.xml
new file mode 100644
index 0000000..ed9a519
--- /dev/null
+++ b/packages/BackupRestoreConfirmation/AndroidManifest.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+** Copyright 2011, 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.android.backupconfirm" >
+
+ <uses-permission android:name="android.permission.BACKUP" />
+
+ <application android:allowClearUserData="false"
+ android:killAfterRestore="false"
+ android:permission="android.permission.CONFIRM_FULL_BACKUP" >
+
+ <activity android:name=".BackupRestoreConfirmation"
+ android:windowSoftInputMode="stateAlwaysHidden"
+ android:excludeFromRecents="true"
+ android:exported="true" >
+ </activity>
+ </application>
+</manifest>
diff --git a/packages/BackupRestoreConfirmation/res/layout/confirm_backup.xml b/packages/BackupRestoreConfirmation/res/layout/confirm_backup.xml
new file mode 100644
index 0000000..109cfff
--- /dev/null
+++ b/packages/BackupRestoreConfirmation/res/layout/confirm_backup.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+/*
+ * Copyright (C) 2011, 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.
+ */
+-->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:padding="10dp" >
+
+ <TextView android:id="@+id/confirm_text"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="30dp"
+ android:text="@string/backup_confirm_text" />
+
+ <TextView android:id="@+id/package_name"
+ android:layout_width="match_parent"
+ android:layout_height="20dp"
+ android:layout_marginLeft="30dp"
+ android:layout_below="@id/confirm_text"
+ android:layout_marginBottom="30dp" />
+
+ <Button android:id="@+id/button_allow"
+ android:text="@string/allow_backup_button_label"
+ android:layout_below="@id/package_name"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content" />
+
+ <Button android:id="@+id/button_deny"
+ android:text="@string/deny_backup_button_label"
+ android:layout_below="@id/package_name"
+ android:layout_toRightOf="@id/button_allow"
+ android:layout_alignTop="@id/button_allow"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content" />
+
+</RelativeLayout>
diff --git a/packages/BackupRestoreConfirmation/res/layout/confirm_restore.xml b/packages/BackupRestoreConfirmation/res/layout/confirm_restore.xml
new file mode 100644
index 0000000..a1f9a4a
--- /dev/null
+++ b/packages/BackupRestoreConfirmation/res/layout/confirm_restore.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+/*
+ * Copyright (C) 2011, 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.
+ */
+-->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:padding="10dp" >
+
+ <TextView android:id="@+id/confirm_text"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="30dp"
+ android:text="@string/restore_confirm_text" />
+
+ <TextView android:id="@+id/package_name"
+ android:layout_width="match_parent"
+ android:layout_height="20dp"
+ android:layout_marginLeft="30dp"
+ android:layout_below="@id/confirm_text"
+ android:layout_marginBottom="30dp" />
+
+ <Button android:id="@+id/button_allow"
+ android:text="@string/allow_restore_button_label"
+ android:layout_below="@id/package_name"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content" />
+
+ <Button android:id="@+id/button_deny"
+ android:text="@string/deny_restore_button_label"
+ android:layout_below="@id/package_name"
+ android:layout_toRightOf="@id/button_allow"
+ android:layout_alignTop="@id/button_allow"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content" />
+
+</RelativeLayout>
diff --git a/packages/BackupRestoreConfirmation/res/values/strings.xml b/packages/BackupRestoreConfirmation/res/values/strings.xml
new file mode 100644
index 0000000..3d85e86
--- /dev/null
+++ b/packages/BackupRestoreConfirmation/res/values/strings.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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">
+
+ <!-- Text for message to user that a full backup has been requested, and must be confirmed. -->
+ <string name="backup_confirm_text">A full backup of all data to a connected desktop computer has been requested. Do you want to allow this to happen\?\n\nIf you did not request the backup yourself, do not allow the operation to proceed.</string>
+ <!-- Button to allow a requested full backup to occur -->
+ <string name="allow_backup_button_label">Back up my data</string>
+ <!-- Button to refuse to allow the requested full backup -->
+ <string name="deny_backup_button_label">Do not back up</string>
+
+ <!-- Text for message to user that a full restore has been requested, and must be confirmed. -->
+ <string name="restore_confirm_text">A full restore of all data from a connected desktop computer has been requested. Do you want to allow this to happen\?\n\nIf you did not request the restore yourself, do not allow the operation to proceed. This will replace any data currently on the device!</string>
+ <!-- Button to allow a requested full restore to occur -->
+ <string name="allow_restore_button_label">Restore my data</string>
+ <!-- Button to refuse to allow the requested full restore -->
+ <string name="deny_restore_button_label">Do not restore</string>
+
+</resources>
diff --git a/packages/BackupRestoreConfirmation/src/com/android/backupconfirm/BackupRestoreConfirmation.java b/packages/BackupRestoreConfirmation/src/com/android/backupconfirm/BackupRestoreConfirmation.java
new file mode 100644
index 0000000..805b905
--- /dev/null
+++ b/packages/BackupRestoreConfirmation/src/com/android/backupconfirm/BackupRestoreConfirmation.java
@@ -0,0 +1,237 @@
+/*
+ * Copyright (C) 2011 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.android.backupconfirm;
+
+import android.app.Activity;
+import android.app.backup.FullBackup;
+import android.app.backup.IBackupManager;
+import android.app.backup.IFullBackupRestoreObserver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.util.Slog;
+import android.view.View;
+import android.widget.Button;
+import android.widget.TextView;
+import android.widget.Toast;
+
+/**
+ * Confirm with the user that a requested full backup/restore operation is legitimate.
+ * Any attempt to perform a full backup/restore will launch this UI and wait for a
+ * designated timeout interval (nominally 30 seconds) for the user to confirm. If the
+ * user fails to respond within the timeout period, or explicitly refuses the operation
+ * within the UI presented here, no data will be transferred off the device.
+ *
+ * Note that the fully scoped name of this class is baked into the backup manager service.
+ *
+ * @hide
+ */
+public class BackupRestoreConfirmation extends Activity {
+ static final String TAG = "BackupRestoreConfirmation";
+ static final boolean DEBUG = true;
+
+ static final int MSG_START_BACKUP = 1;
+ static final int MSG_BACKUP_PACKAGE = 2;
+ static final int MSG_END_BACKUP = 3;
+ static final int MSG_START_RESTORE = 11;
+ static final int MSG_RESTORE_PACKAGE = 12;
+ static final int MSG_END_RESTORE = 13;
+ static final int MSG_TIMEOUT = 100;
+
+ Handler mHandler;
+ IBackupManager mBackupManager;
+ FullObserver mObserver;
+ int mToken;
+
+ TextView mStatusView;
+ Button mAllowButton;
+ Button mDenyButton;
+
+ // Handler for dealing with observer callbacks on the main thread
+ class ObserverHandler extends Handler {
+ Context mContext;
+ ObserverHandler(Context context) {
+ mContext = context;
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case MSG_START_BACKUP: {
+ Toast.makeText(mContext, "!!! Backup starting !!!", Toast.LENGTH_LONG);
+ }
+ break;
+
+ case MSG_BACKUP_PACKAGE: {
+ String name = (String) msg.obj;
+ mStatusView.setText(name);
+ }
+ break;
+
+ case MSG_END_BACKUP: {
+ Toast.makeText(mContext, "!!! Backup ended !!!", Toast.LENGTH_SHORT);
+ }
+ break;
+
+ case MSG_START_RESTORE: {
+ Toast.makeText(mContext, "!!! Restore starting !!!", Toast.LENGTH_LONG);
+ }
+ break;
+
+ case MSG_RESTORE_PACKAGE: {
+ }
+ break;
+
+ case MSG_END_RESTORE: {
+ Toast.makeText(mContext, "!!! Restore ended !!!", Toast.LENGTH_SHORT);
+ }
+ break;
+
+ case MSG_TIMEOUT: {
+ }
+ break;
+ }
+ }
+ }
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+
+ final Intent intent = getIntent();
+ final String action = intent.getAction();
+
+ int layoutId;
+ if (action.equals(FullBackup.FULL_BACKUP_INTENT_ACTION)) {
+ layoutId = R.layout.confirm_backup;
+ } else if (action.equals(FullBackup.FULL_RESTORE_INTENT_ACTION)) {
+ layoutId = R.layout.confirm_restore;
+ } else {
+ Slog.w(TAG, "Backup/restore confirmation activity launched with invalid action!");
+ finish();
+ return;
+ }
+
+ mToken = intent.getIntExtra(FullBackup.CONF_TOKEN_INTENT_EXTRA, -1);
+ if (mToken < 0) {
+ Slog.e(TAG, "Backup/restore confirmation requested but no token passed!");
+ finish();
+ return;
+ }
+
+ mBackupManager = IBackupManager.Stub.asInterface(ServiceManager.getService(Context.BACKUP_SERVICE));
+
+ mHandler = new ObserverHandler(getApplicationContext());
+ mObserver = new FullObserver();
+
+ setContentView(layoutId);
+
+ // Same resource IDs for each layout variant (backup / restore)
+ mStatusView = (TextView) findViewById(R.id.package_name);
+ mAllowButton = (Button) findViewById(R.id.button_allow);
+ mDenyButton = (Button) findViewById(R.id.button_deny);
+
+ mAllowButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ try {
+ mBackupManager.acknowledgeFullBackupOrRestore(mToken, true, mObserver);
+ } catch (RemoteException e) {
+ // TODO: bail gracefully if we can't contact the backup manager
+ }
+ mAllowButton.setEnabled(false);
+ mDenyButton.setEnabled(false);
+ }
+ });
+
+ mDenyButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ try {
+ mBackupManager.acknowledgeFullBackupOrRestore(mToken, false, mObserver);
+ } catch (RemoteException e) {
+ // TODO: bail gracefully if we can't contact the backup manager
+ }
+ mAllowButton.setEnabled(false);
+ mDenyButton.setEnabled(false);
+ }
+ });
+ }
+
+ @Override
+ public void onStop() {
+ super.onStop();
+
+ // We explicitly equate departure from the UI with refusal. This includes the
+ // implicit configuration-changed stop/restart cycle.
+ try {
+ mBackupManager.acknowledgeFullBackupOrRestore(mToken, false, null);
+ } catch (RemoteException e) {
+ // if this fails we'll still time out with no acknowledgment
+ }
+ finish();
+ }
+
+ /**
+ * The observer binder for showing backup/restore progress. This binder just bounces
+ * the notifications onto the main thread.
+ */
+ class FullObserver extends IFullBackupRestoreObserver.Stub {
+ //
+ // IFullBackupRestoreObserver implementation
+ //
+ @Override
+ public void onStartBackup() throws RemoteException {
+ mHandler.sendEmptyMessage(MSG_START_BACKUP);
+ }
+
+ @Override
+ public void onBackupPackage(String name) throws RemoteException {
+ mHandler.sendMessage(mHandler.obtainMessage(MSG_BACKUP_PACKAGE, name));
+ }
+
+ @Override
+ public void onEndBackup() throws RemoteException {
+ mHandler.sendEmptyMessage(MSG_END_BACKUP);
+ }
+
+ @Override
+ public void onStartRestore() throws RemoteException {
+ mHandler.sendEmptyMessage(MSG_START_RESTORE);
+ }
+
+ @Override
+ public void onRestorePackage(String name) throws RemoteException {
+ mHandler.sendMessage(mHandler.obtainMessage(MSG_RESTORE_PACKAGE, name));
+ }
+
+ @Override
+ public void onEndRestore() throws RemoteException {
+ mHandler.sendEmptyMessage(MSG_END_RESTORE);
+ }
+
+ @Override
+ public void onTimeout() throws RemoteException {
+ mHandler.sendEmptyMessage(MSG_TIMEOUT);
+ }
+ }
+}