2 * Copyright (C) 2011 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.settings;
19 import android.app.Activity;
20 import android.app.backup.IBackupManager;
21 import android.os.Bundle;
22 import android.os.RemoteException;
23 import android.os.ServiceManager;
24 import android.util.Log;
25 import android.view.View;
26 import android.view.View.OnClickListener;
27 import android.widget.Button;
28 import android.widget.TextView;
29 import android.widget.Toast;
31 public class SetFullBackupPassword extends Activity {
32 static final String TAG = "SetFullBackupPassword";
34 IBackupManager mBackupManager;
35 TextView mCurrentPw, mNewPw, mConfirmNewPw;
38 OnClickListener mButtonListener = new OnClickListener() {
40 public void onClick(View v) {
42 final String curPw = mCurrentPw.getText().toString();
43 final String newPw = mNewPw.getText().toString();
44 final String confirmPw = mConfirmNewPw.getText().toString();
46 if (!newPw.equals(confirmPw)) {
47 // Mismatch between new pw and its confirmation re-entry
48 Log.i(TAG, "password mismatch");
49 Toast.makeText(SetFullBackupPassword.this,
50 R.string.local_backup_password_toast_confirmation_mismatch,
51 Toast.LENGTH_LONG).show();
55 // TODO: should we distinguish cases of has/hasn't set a pw before?
57 if (setBackupPassword(curPw, newPw)) {
59 Log.i(TAG, "password set successfully");
60 Toast.makeText(SetFullBackupPassword.this,
61 R.string.local_backup_password_toast_success,
62 Toast.LENGTH_LONG).show();
65 // failure -- bad existing pw, usually
66 Log.i(TAG, "failure; password mismatch?");
67 Toast.makeText(SetFullBackupPassword.this,
68 R.string.local_backup_password_toast_validation_failure,
69 Toast.LENGTH_LONG).show();
71 } else if (v == mCancel) {
74 Log.w(TAG, "Click on unknown view");
80 public void onCreate(Bundle icicle) {
81 super.onCreate(icicle);
83 mBackupManager = IBackupManager.Stub.asInterface(ServiceManager.getService("backup"));
85 setContentView(R.layout.set_backup_pw);
87 mCurrentPw = (TextView) findViewById(R.id.current_backup_pw);
88 mNewPw = (TextView) findViewById(R.id.new_backup_pw);
89 mConfirmNewPw = (TextView) findViewById(R.id.confirm_new_backup_pw);
91 mCancel = (Button) findViewById(R.id.backup_pw_cancel_button);
92 mSet = (Button) findViewById(R.id.backup_pw_set_button);
94 mCancel.setOnClickListener(mButtonListener);
95 mSet.setOnClickListener(mButtonListener);
98 private boolean setBackupPassword(String currentPw, String newPw) {
100 return mBackupManager.setBackupPassword(currentPw, newPw);
101 } catch (RemoteException e) {
102 Log.e(TAG, "Unable to communicate with backup manager");