blob: b6a03d5062077700cc86cdfc61861e72726546b4 [file] [log] [blame]
Christopher Tate4f338782011-07-25 12:09:10 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17package com.android.settings;
18
19import android.app.Activity;
20import android.app.backup.IBackupManager;
21import android.os.Bundle;
22import android.os.RemoteException;
23import android.os.ServiceManager;
xiamin3c2956a2018-07-10 10:48:56 +080024import android.text.TextUtils;
Christopher Tate4f338782011-07-25 12:09:10 -070025import android.util.Log;
26import android.view.View;
27import android.view.View.OnClickListener;
28import android.widget.Button;
29import android.widget.TextView;
30import android.widget.Toast;
31
32public class SetFullBackupPassword extends Activity {
33 static final String TAG = "SetFullBackupPassword";
34
35 IBackupManager mBackupManager;
36 TextView mCurrentPw, mNewPw, mConfirmNewPw;
37 Button mCancel, mSet;
38
39 OnClickListener mButtonListener = new OnClickListener() {
40 @Override
41 public void onClick(View v) {
42 if (v == mSet) {
43 final String curPw = mCurrentPw.getText().toString();
44 final String newPw = mNewPw.getText().toString();
45 final String confirmPw = mConfirmNewPw.getText().toString();
46
47 if (!newPw.equals(confirmPw)) {
48 // Mismatch between new pw and its confirmation re-entry
xiamin3c2956a2018-07-10 10:48:56 +080049 Log.i(TAG, "password mismatch");
Christopher Tate4f338782011-07-25 12:09:10 -070050 Toast.makeText(SetFullBackupPassword.this,
Christopher Tate2d6497d2012-06-19 15:44:15 -070051 R.string.local_backup_password_toast_confirmation_mismatch,
Christopher Tate4f338782011-07-25 12:09:10 -070052 Toast.LENGTH_LONG).show();
53 return;
54 }
55
56 // TODO: should we distinguish cases of has/hasn't set a pw before?
57
58 if (setBackupPassword(curPw, newPw)) {
59 // success
xiamin3c2956a2018-07-10 10:48:56 +080060 Log.i(TAG, "password set successfully");
Christopher Tate4f338782011-07-25 12:09:10 -070061 Toast.makeText(SetFullBackupPassword.this,
Christopher Tate2d6497d2012-06-19 15:44:15 -070062 R.string.local_backup_password_toast_success,
Christopher Tate4f338782011-07-25 12:09:10 -070063 Toast.LENGTH_LONG).show();
64 finish();
65 } else {
66 // failure -- bad existing pw, usually
xiamin3c2956a2018-07-10 10:48:56 +080067 Log.i(TAG, "failure; password mismatch?");
Christopher Tate4f338782011-07-25 12:09:10 -070068 Toast.makeText(SetFullBackupPassword.this,
Christopher Tate2d6497d2012-06-19 15:44:15 -070069 R.string.local_backup_password_toast_validation_failure,
Christopher Tate4f338782011-07-25 12:09:10 -070070 Toast.LENGTH_LONG).show();
71 }
72 } else if (v == mCancel) {
73 finish();
74 } else {
75 Log.w(TAG, "Click on unknown view");
76 }
77 }
78 };
79
80 @Override
81 public void onCreate(Bundle icicle) {
82 super.onCreate(icicle);
83
84 mBackupManager = IBackupManager.Stub.asInterface(ServiceManager.getService("backup"));
85
86 setContentView(R.layout.set_backup_pw);
87
88 mCurrentPw = (TextView) findViewById(R.id.current_backup_pw);
89 mNewPw = (TextView) findViewById(R.id.new_backup_pw);
90 mConfirmNewPw = (TextView) findViewById(R.id.confirm_new_backup_pw);
91
92 mCancel = (Button) findViewById(R.id.backup_pw_cancel_button);
93 mSet = (Button) findViewById(R.id.backup_pw_set_button);
94
95 mCancel.setOnClickListener(mButtonListener);
96 mSet.setOnClickListener(mButtonListener);
97 }
98
99 private boolean setBackupPassword(String currentPw, String newPw) {
xiamin3c2956a2018-07-10 10:48:56 +0800100 // new password can't be empty
101 if (TextUtils.isEmpty(newPw)) {
102 return false;
103 }
104
Christopher Tate4f338782011-07-25 12:09:10 -0700105 try {
106 return mBackupManager.setBackupPassword(currentPw, newPw);
107 } catch (RemoteException e) {
108 Log.e(TAG, "Unable to communicate with backup manager");
109 return false;
110 }
111 }
112}