org.chromium.chrome.browser.childaccounts.ChildAccountService Java Examples

The following examples show how to use org.chromium.chrome.browser.childaccounts.ChildAccountService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SyncController.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Updates sync to reflect the state of the Android sync settings.
 */
private void updateSyncStateFromAndroid() {
    boolean isSyncEnabled = AndroidSyncSettings.isSyncEnabled(mContext);
    if (isSyncEnabled == mProfileSyncService.isSyncRequested()) return;
    if (isSyncEnabled) {
        mProfileSyncService.requestStart();
    } else {
        if (ChildAccountService.isChildAccount()) {
            // For child accounts, Sync needs to stay enabled, so we reenable it in settings.
            // TODO(bauerb): Remove the dependency on child account code and instead go through
            // prefs (here and in the Sync customization UI).
            AndroidSyncSettings.enableChromeSync(mContext);
        } else {
            if (AndroidSyncSettings.isMasterSyncEnabled(mContext)) {
                RecordHistogram.recordEnumeratedHistogram("Sync.StopSource",
                        StopSource.ANDROID_CHROME_SYNC, StopSource.STOP_SOURCE_LIMIT);
            } else {
                RecordHistogram.recordEnumeratedHistogram("Sync.StopSource",
                        StopSource.ANDROID_MASTER_SYNC, StopSource.STOP_SOURCE_LIMIT);
            }
            mProfileSyncService.requestStop();
        }
    }
}
 
Example #2
Source File: AccountManagementFragment.java    From delion with Apache License 2.0 5 votes vote down vote up
private void updateAccountsList() {
    PreferenceScreen prefScreen = getPreferenceScreen();
    if (prefScreen == null) return;

    for (int i = 0; i < mAccountsListPreferences.size(); i++) {
        prefScreen.removePreference(mAccountsListPreferences.get(i));
    }
    mAccountsListPreferences.clear();

    final Preferences activity = (Preferences) getActivity();
    Account[] accounts = AccountManagerHelper.get(activity).getGoogleAccounts();
    int nextPrefOrder = FIRST_ACCOUNT_PREF_ORDER;

    for (Account account : accounts) {
        ChromeBasePreference pref = new ChromeBasePreference(activity);
        pref.setSelectable(false);
        pref.setTitle(account.name);

        boolean isChildAccount = ChildAccountService.isChildAccount();

        pref.setIcon(new BitmapDrawable(getResources(),
                isChildAccount ? getBadgedUserPicture(account.name, getResources()) :
                    getUserPicture(account.name, getResources())));

        pref.setOrder(nextPrefOrder++);
        prefScreen.addPreference(pref);
        mAccountsListPreferences.add(pref);
    }
}
 
Example #3
Source File: AccountManagementFragment.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private void updateAccountsList() {
    PreferenceScreen prefScreen = getPreferenceScreen();
    if (prefScreen == null) return;

    for (int i = 0; i < mAccountsListPreferences.size(); i++) {
        prefScreen.removePreference(mAccountsListPreferences.get(i));
    }
    mAccountsListPreferences.clear();

    final Preferences activity = (Preferences) getActivity();
    Account[] accounts = AccountManagerHelper.get(activity).getGoogleAccounts();
    int nextPrefOrder = FIRST_ACCOUNT_PREF_ORDER;

    for (Account account : accounts) {
        ChromeBasePreference pref = new ChromeBasePreference(activity);
        pref.setSelectable(false);
        pref.setTitle(account.name);

        boolean isChildAccount = ChildAccountService.isChildAccount();

        pref.setIcon(new BitmapDrawable(getResources(),
                isChildAccount ? getBadgedUserPicture(account.name, getResources()) :
                    getUserPicture(account.name, getResources())));

        pref.setOrder(nextPrefOrder++);
        prefScreen.addPreference(pref);
        mAccountsListPreferences.add(pref);
    }
}
 
Example #4
Source File: AndroidEduAndChildAccountHelper.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * Starts fetching the Android EDU and child accounts information.
 * Calls onParametersReady() once the information is fetched.
 * @param appContext The application context.
 */
public void start(Context appContext) {
    ChildAccountService.checkHasChildAccount(appContext, this);
    ((ChromeApplication) appContext).checkIsAndroidEduDevice(this);
    // TODO(aruslan): Should we start a watchdog to kill if Child/Edu stuff takes too long?
}
 
Example #5
Source File: AccountManagementFragment.java    From delion with Apache License 2.0 4 votes vote down vote up
private void configureSignOutSwitch() {
    boolean isChildAccount = ChildAccountService.isChildAccount();

    Preference signOutSwitch = findPreference(PREF_SIGN_OUT);
    if (isChildAccount) {
        getPreferenceScreen().removePreference(signOutSwitch);
    } else {
        signOutSwitch.setEnabled(getSignOutAllowedPreferenceValue(getActivity()));
        signOutSwitch.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                if (!isVisible() || !isResumed()) return false;

                if (ChromeSigninController.get(getActivity()).isSignedIn()
                        && getSignOutAllowedPreferenceValue(getActivity())) {
                    AccountManagementScreenHelper.logEvent(
                            ProfileAccountManagementMetrics.TOGGLE_SIGNOUT,
                            mGaiaServiceType);

                    String managementDomain =
                            SigninManager.get(getActivity()).getManagementDomain();
                    if (managementDomain != null) {
                        // Show the 'You are signing out of a managed account' dialog.
                        ConfirmManagedSyncDataDialog.showSignOutFromManagedAccountDialog(
                                AccountManagementFragment.this, getFragmentManager(),
                                getResources(), managementDomain);
                    } else {
                        // Show the 'You are signing out' dialog.
                        SignOutDialogFragment signOutFragment = new SignOutDialogFragment();
                        Bundle args = new Bundle();
                        args.putInt(SHOW_GAIA_SERVICE_TYPE_EXTRA, mGaiaServiceType);
                        signOutFragment.setArguments(args);

                        signOutFragment.setTargetFragment(AccountManagementFragment.this, 0);
                        signOutFragment.show(getFragmentManager(), SIGN_OUT_DIALOG_TAG);
                    }

                    return true;
                }

                return false;
            }

        });
    }
}
 
Example #6
Source File: AccountManagementFragment.java    From delion with Apache License 2.0 4 votes vote down vote up
private void configureChildAccountPreferences() {
    Preference parentAccounts = findPreference(PREF_PARENT_ACCOUNTS);
    Preference childContent = findPreference(PREF_CHILD_CONTENT);
    Preference childSafeSites = findPreference(PREF_CHILD_SAFE_SITES);
    if (ChildAccountService.isChildAccount()) {
        Resources res = getActivity().getResources();
        PrefServiceBridge prefService = PrefServiceBridge.getInstance();

        String firstParent = prefService.getSupervisedUserCustodianEmail();
        String secondParent = prefService.getSupervisedUserSecondCustodianEmail();
        String parentText;

        if (!secondParent.isEmpty()) {
            parentText = res.getString(R.string.account_management_two_parent_names,
                    firstParent, secondParent);
        } else if (!firstParent.isEmpty()) {
            parentText = res.getString(R.string.account_management_one_parent_name,
                    firstParent);
        } else {
            parentText = res.getString(R.string.account_management_no_parental_data);
        }
        parentAccounts.setSummary(parentText);
        parentAccounts.setSelectable(false);

        final boolean unapprovedContentBlocked =
                prefService.getDefaultSupervisedUserFilteringBehavior()
                == PrefServiceBridge.SUPERVISED_USER_FILTERING_BLOCK;
        final String contentText = res.getString(
                unapprovedContentBlocked ? R.string.account_management_child_content_approved
                        : R.string.account_management_child_content_all);
        childContent.setSummary(contentText);
        childContent.setSelectable(false);

        final String safeSitesText = res.getString(
                prefService.isSupervisedUserSafeSitesEnabled()
                        ? R.string.text_on : R.string.text_off);
        childSafeSites.setSummary(safeSitesText);
        childSafeSites.setSelectable(false);
    } else {
        PreferenceScreen prefScreen = getPreferenceScreen();
        prefScreen.removePreference(findPreference(PREF_PARENTAL_SETTINGS));
        prefScreen.removePreference(parentAccounts);
        prefScreen.removePreference(childContent);
        prefScreen.removePreference(childSafeSites);
    }
}
 
Example #7
Source File: SyncPreference.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * Return a short summary of the current sync status.
 */
static String getSyncStatusSummary(Context context) {
    if (!ChromeSigninController.get(context).isSignedIn()) return "";

    ProfileSyncService profileSyncService = ProfileSyncService.get();
    Resources res = context.getResources();

    if (ChildAccountService.isChildAccount()) {
        return res.getString(R.string.kids_account);
    }

    if (!AndroidSyncSettings.isMasterSyncEnabled(context)) {
        return res.getString(R.string.sync_android_master_sync_disabled);
    }

    if (profileSyncService == null) {
        return res.getString(R.string.sync_is_disabled);
    }

    if (profileSyncService.getAuthError() != GoogleServiceAuthError.State.NONE) {
        return res.getString(profileSyncService.getAuthError().getMessage());
    }

    // TODO(crbug/557784): Surface IDS_SYNC_UPGRADE_CLIENT string when we require the user
    // to upgrade

    boolean syncEnabled = AndroidSyncSettings.isSyncEnabled(context);

    if (syncEnabled) {
        if (!profileSyncService.isSyncActive()) {
            return res.getString(R.string.sync_setup_progress);
        }

        if (profileSyncService.isPassphraseRequiredForDecryption()) {
            return res.getString(R.string.sync_need_passphrase);
        }

        Account account = ChromeSigninController.get(context).getSignedInUser();
        return String.format(
                context.getString(R.string.account_management_sync_summary), account.name);
    }

    return context.getString(R.string.sync_is_disabled);
}
 
Example #8
Source File: SyncCustomizationFragment.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * @return Whether Sync can be disabled.
 */
private boolean canDisableSync() {
    return !ChildAccountService.isChildAccount();
}
 
Example #9
Source File: AndroidEduAndChildAccountHelper.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Starts fetching the Android EDU and child accounts information.
 * Calls onParametersReady() once the information is fetched.
 * @param appContext The application context.
 */
public void start(Context appContext) {
    ChildAccountService.checkHasChildAccount(appContext, this);
    ((ChromeApplication) appContext).checkIsAndroidEduDevice(this);
    // TODO(aruslan): Should we start a watchdog to kill if Child/Edu stuff takes too long?
}
 
Example #10
Source File: AccountManagementFragment.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private void configureSignOutSwitch() {
    boolean isChildAccount = ChildAccountService.isChildAccount();

    Preference signOutSwitch = findPreference(PREF_SIGN_OUT);
    if (isChildAccount) {
        getPreferenceScreen().removePreference(signOutSwitch);
    } else {
        signOutSwitch.setEnabled(getSignOutAllowedPreferenceValue(getActivity()));
        signOutSwitch.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                if (!isVisible() || !isResumed()) return false;

                if (ChromeSigninController.get(getActivity()).isSignedIn()
                        && getSignOutAllowedPreferenceValue(getActivity())) {
                    AccountManagementScreenHelper.logEvent(
                            ProfileAccountManagementMetrics.TOGGLE_SIGNOUT,
                            mGaiaServiceType);

                    String managementDomain =
                            SigninManager.get(getActivity()).getManagementDomain();
                    if (managementDomain != null) {
                        // Show the 'You are signing out of a managed account' dialog.
                        ConfirmManagedSyncDataDialog.showSignOutFromManagedAccountDialog(
                                AccountManagementFragment.this, getFragmentManager(),
                                getResources(), managementDomain);
                    } else {
                        // Show the 'You are signing out' dialog.
                        SignOutDialogFragment signOutFragment = new SignOutDialogFragment();
                        Bundle args = new Bundle();
                        args.putInt(SHOW_GAIA_SERVICE_TYPE_EXTRA, mGaiaServiceType);
                        signOutFragment.setArguments(args);

                        signOutFragment.setTargetFragment(AccountManagementFragment.this, 0);
                        signOutFragment.show(getFragmentManager(), SIGN_OUT_DIALOG_TAG);
                    }

                    return true;
                }

                return false;
            }

        });
    }
}
 
Example #11
Source File: AccountManagementFragment.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private void configureChildAccountPreferences() {
    Preference parentAccounts = findPreference(PREF_PARENT_ACCOUNTS);
    Preference childContent = findPreference(PREF_CHILD_CONTENT);
    Preference childSafeSites = findPreference(PREF_CHILD_SAFE_SITES);
    if (ChildAccountService.isChildAccount()) {
        Resources res = getActivity().getResources();
        PrefServiceBridge prefService = PrefServiceBridge.getInstance();

        String firstParent = prefService.getSupervisedUserCustodianEmail();
        String secondParent = prefService.getSupervisedUserSecondCustodianEmail();
        String parentText;

        if (!secondParent.isEmpty()) {
            parentText = res.getString(R.string.account_management_two_parent_names,
                    firstParent, secondParent);
        } else if (!firstParent.isEmpty()) {
            parentText = res.getString(R.string.account_management_one_parent_name,
                    firstParent);
        } else {
            parentText = res.getString(R.string.account_management_no_parental_data);
        }
        parentAccounts.setSummary(parentText);
        parentAccounts.setSelectable(false);

        final boolean unapprovedContentBlocked =
                prefService.getDefaultSupervisedUserFilteringBehavior()
                == PrefServiceBridge.SUPERVISED_USER_FILTERING_BLOCK;
        final String contentText = res.getString(
                unapprovedContentBlocked ? R.string.account_management_child_content_approved
                        : R.string.account_management_child_content_all);
        childContent.setSummary(contentText);
        childContent.setSelectable(false);

        final String safeSitesText = res.getString(
                prefService.isSupervisedUserSafeSitesEnabled()
                        ? R.string.text_on : R.string.text_off);
        childSafeSites.setSummary(safeSitesText);
        childSafeSites.setSelectable(false);
    } else {
        PreferenceScreen prefScreen = getPreferenceScreen();
        prefScreen.removePreference(findPreference(PREF_PARENTAL_SETTINGS));
        prefScreen.removePreference(parentAccounts);
        prefScreen.removePreference(childContent);
        prefScreen.removePreference(childSafeSites);
    }
}
 
Example #12
Source File: SyncPreference.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Return a short summary of the current sync status.
 */
static String getSyncStatusSummary(Context context) {
    if (!ChromeSigninController.get(context).isSignedIn()) return "";

    ProfileSyncService profileSyncService = ProfileSyncService.get();
    Resources res = context.getResources();

    if (ChildAccountService.isChildAccount()) {
        return res.getString(R.string.kids_account);
    }

    if (!AndroidSyncSettings.isMasterSyncEnabled(context)) {
        return res.getString(R.string.sync_android_master_sync_disabled);
    }

    if (profileSyncService == null) {
        return res.getString(R.string.sync_is_disabled);
    }

    if (profileSyncService.getAuthError() != GoogleServiceAuthError.State.NONE) {
        return res.getString(profileSyncService.getAuthError().getMessage());
    }

    if (profileSyncService.getProtocolErrorClientAction()
            == ProtocolErrorClientAction.UPGRADE_CLIENT) {
        return res.getString(
                R.string.sync_error_upgrade_client, BuildInfo.getPackageLabel(context));
    }

    if (profileSyncService.hasUnrecoverableError()) {
        return res.getString(R.string.sync_error_generic);
    }

    boolean syncEnabled = AndroidSyncSettings.isSyncEnabled(context);

    if (syncEnabled) {
        if (!profileSyncService.isSyncActive()) {
            return res.getString(R.string.sync_setup_progress);
        }

        if (profileSyncService.isPassphraseRequiredForDecryption()) {
            return res.getString(R.string.sync_need_passphrase);
        }

        Account account = ChromeSigninController.get(context).getSignedInUser();
        return String.format(
                context.getString(R.string.account_management_sync_summary), account.name);
    }

    return context.getString(R.string.sync_is_disabled);
}
 
Example #13
Source File: SyncCustomizationFragment.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * @return Whether Sync can be disabled.
 */
private boolean canDisableSync() {
    return !ChildAccountService.isChildAccount();
}
 
Example #14
Source File: AndroidEduAndChildAccountHelper.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Starts fetching the Android EDU and child accounts information.
 * Calls onParametersReady() once the information is fetched.
 * @param appContext The application context.
 */
public void start(Context appContext) {
    ChildAccountService.checkHasChildAccount(appContext, this);
    AppHooks.get().checkIsAndroidEduDevice(this);
    // TODO(aruslan): Should we start a watchdog to kill if Child/Edu stuff takes too long?
}
 
Example #15
Source File: SupervisedUserContentProvider.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
void listenForChildAccountStatusChange(Callback<Boolean> callback) {
    ChildAccountService.listenForStatusChange(callback);
}