Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/child_accounts/ResetDataActivity.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/child_accounts/ResetDataActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/child_accounts/ResetDataActivity.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a8907f13099f3885de3dcaafe199f79b5ef4819e |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/child_accounts/ResetDataActivity.java |
| @@ -0,0 +1,73 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chrome.browser.child_accounts; |
| + |
| +import android.annotation.TargetApi; |
| +import android.app.Activity; |
| +import android.app.ActivityManager; |
| +import android.content.Context; |
| +import android.os.Build; |
| +import android.os.Bundle; |
| +import android.support.v4.app.DialogFragment; |
| +import android.support.v4.app.FragmentActivity; |
| + |
| +import org.chromium.chrome.browser.firstrun.FirstRunStatus; |
| + |
| +/** |
| + * An activity that prompts the user to reset all data in Chrome, |
| + * as part of the child account setup. |
| + */ |
| +public class ResetDataActivity extends FragmentActivity implements |
| + ResetDataDialogFragment.DialogListener { |
| + |
| + private static final String FRAGMENT_TAG = "reset-data"; |
| + |
| + @Override |
| + public void onCreate(Bundle savedInstanceState) { |
| + super.onCreate(savedInstanceState); |
| + |
| + // If the user has not been through the first run yet, we assume there is no data of |
| + // interest to clear, so we immediately return success. |
| + if (!FirstRunStatus.getFirstRunFlowComplete(this)) { |
| + returnResult(true); |
| + return; |
| + } |
| + DialogFragment dialog = new ResetDataDialogFragment(this, this); |
| + dialog.show(getSupportFragmentManager(), FRAGMENT_TAG); |
| + } |
| + |
| + @Override |
| + public void onResetData(DialogFragment dialog) { |
| + if (!resetData()) { |
| + returnResult(false); |
| + return; |
| + } |
| + returnResult(true); |
| + } |
| + |
| + @Override |
| + public void onKeepData(DialogFragment dialog) { |
| + returnResult(true); |
| + } |
| + |
| + @Override |
| + public void onCancel(DialogFragment dialog) { |
| + returnResult(false); |
| + } |
| + |
| + @TargetApi(Build.VERSION_CODES.KITKAT) |
| + private boolean resetData() { |
| + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { |
|
aurimas (slooooooooow)
2015/06/09 17:45:03
What will happen on JB devices?
Bernhard Bauer
2015/06/15 17:07:29
We will return an error. In practice, this shouldn
|
| + return false; |
| + } |
| + ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); |
| + return am.clearApplicationUserData(); |
| + } |
| + |
| + private void returnResult(boolean success) { |
| + setResult(success ? Activity.RESULT_OK : Activity.RESULT_CANCELED); |
| + finish(); |
| + } |
| +} |