Skip to content

Commit

Permalink
Upstream 3.0.11 source
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-mak committed Aug 11, 2016
2 parents 064b1c7 + 30a6b9f commit 5b8297e
Show file tree
Hide file tree
Showing 23 changed files with 1,531 additions and 691 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ext {
// exactly 1 digit
versionMinor = 0
// exactly 2 digits
versionBuild = 9
versionBuild = 11
}

android {
Expand Down
38 changes: 27 additions & 11 deletions app/src/main/java/com/afwsamples/testdpc/EnableProfileActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.StringRes;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import android.view.View;
Expand Down Expand Up @@ -54,7 +55,7 @@ public class EnableProfileActivity extends Activity implements NavigationBar.Nav
private Button mFinishButton;
private SetupWizardLayout mSetupWizardLayout;

private boolean mEnableProfileNow;
private CheckInState mCheckinState;

public static final String EXTRA_ENABLE_PROFILE_NOW = "enable_profile_now";
private static final IntentFilter sIntentFilter =
Expand All @@ -64,9 +65,11 @@ public class EnableProfileActivity extends Activity implements NavigationBar.Nav
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mEnableProfileNow = getIntent().getBooleanExtra(EXTRA_ENABLE_PROFILE_NOW, false);

mCheckinState = new CheckInState(this);
if (savedInstanceState == null) {
if (mEnableProfileNow) {
if (getIntent().getBooleanExtra(EXTRA_ENABLE_PROFILE_NOW, false)) {
mCheckinState.setFirstAccountState(CheckInState.FIRST_ACCOUNT_STATE_READY);
ProvisioningUtil.enableProfile(this);
} else {
// Set up an alarm to enable profile in case we do not receive first account ready
Expand Down Expand Up @@ -120,8 +123,7 @@ protected void onResume() {
LocalBroadcastManager.getInstance(this).registerReceiver(mCheckInStateReceiver,
sIntentFilter);
// In case the broadcast is sent before we register the receiver.
CheckInState checkInState = new CheckInState(this);
refreshUi(mEnableProfileNow || checkInState.isFirstAccountReady() /* enableFinish */);
refreshUi();
}

@Override
Expand All @@ -140,16 +142,30 @@ private boolean isAccountMigrated(String addedAccount) {
return false;
}

private void refreshUi(boolean enableFinish) {
private void refreshUi() {
boolean enableFinish;
@StringRes int headerTextResId;
switch (mCheckinState.getFirstAccountState()) {
case CheckInState.FIRST_ACCOUNT_STATE_READY:
enableFinish = true;
headerTextResId = R.string.finish_setup;
break;
case CheckInState.FIRST_ACCOUNT_STATE_TIMEOUT:
enableFinish = true;
headerTextResId = R.string.finish_setup_account_not_ready;
break;
case CheckInState.FIRST_ACCOUNT_STATE_PENDING:
default:
enableFinish = false;
headerTextResId = R.string.waiting_for_first_account_check_in;
break;
}
if (enableFinish) {
mSetupWizardLayout.hideProgressBar();
} else {
mSetupWizardLayout.showProgressBar();
}
mSetupWizardLayout.setHeaderText(
(enableFinish)
? R.string.finish_setup
: R.string.waiting_for_first_account_check_in);
mSetupWizardLayout.setHeaderText(headerTextResId);
mFinishButton.setEnabled(enableFinish);
}

Expand All @@ -167,7 +183,7 @@ class CheckInStateReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Processed the first check-in broadcast, allow user to tap the finish button.
refreshUi(true);
refreshUi();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ public void onReceive(Context context, Intent intent) {
if (FIRST_ACCOUNT_READY_ACTION.equals(action) ||
FIRST_ACCOUNT_READY_TIMEOUT_ACTION.equals(action)) {
CheckInState checkInState = new CheckInState(context);
if (!checkInState.isFirstAccountReady()) {
checkInState.setFirstAccountReady();
if (checkInState.getFirstAccountState() == CheckInState.FIRST_ACCOUNT_STATE_PENDING) {
int nextState;
if (FIRST_ACCOUNT_READY_ACTION.equals(action)) {
nextState = CheckInState.FIRST_ACCOUNT_STATE_READY;
} else {
nextState = CheckInState.FIRST_ACCOUNT_STATE_TIMEOUT;
}
checkInState.setFirstAccountState(nextState);
ProvisioningUtil.enableProfile(context);
}
// This receiver is disabled in ProvisioningUtil.enableProfile, no more code should
Expand Down
15 changes: 12 additions & 3 deletions app/src/main/java/com/afwsamples/testdpc/common/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,17 @@ public static boolean isManagedProfile(Context context, ComponentName admin) {
}
}

public static void disablePreference(Preference preference, int whyResId) {
preference.setEnabled(false);
preference.setSummary(whyResId);
@TargetApi(VERSION_CODES.M)
public static boolean isPrimaryUser(Context context) {
if (isBeforeM()) {
// Assume only DO can be primary user. This is not perfect but the cases in which it is
// wrong are uncommon and require adb to set up.
final DevicePolicyManager dpm =
(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
return dpm.isDeviceOwnerApp(context.getPackageName());
} else {
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
return userManager.isSystemUser();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Copyright (C) 2016 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.afwsamples.testdpc.common.preference;

import android.content.Context;
import android.support.annotation.StringRes;
import android.support.v7.preference.EditTextPreference;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.preference.PreferenceViewHolder;
import android.util.AttributeSet;

/**
* An {@link EditTextPreference} which can be disabled via XML declared constraints.
*
* See {@link DpcPreferenceHelper} for details about constraints.
*/
public class DpcEditTextPreference extends EditTextPreference implements DpcPreferenceBase {
private DpcPreferenceHelper mHelper;

public DpcEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
mHelper = new DpcPreferenceHelper(context, this, attrs);
}

public DpcEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr) {
this(context, attrs, defStyleAttr, 0);
}

public DpcEditTextPreference(Context context, AttributeSet attrs) {
this(context, attrs, android.support.v7.preference.R.attr.editTextPreferenceStyle);
}

public DpcEditTextPreference(Context context) {
this(context, null);
}

@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
mHelper.onBindViewHolder(holder);
}

@Override
protected void onAttachedToHierarchy(PreferenceManager preferenceManager) {
mHelper.onAttachedToHierarchy();
super.onAttachedToHierarchy(preferenceManager);
}

@Override
public void setEnabled(boolean enabled) {
if (enabled && !mHelper.constraintsMet()) {
return; // ignore
}
super.setEnabled(enabled);
}

@Override
public void setMinSdkVersion(int version) {
mHelper.setMinSdkVersion(version);
}

@Override
public void setAdminConstraint(@DpcPreferenceHelper.AdminKind int adminConstraint) {
mHelper.setAdminConstraint(adminConstraint);
}

@Override
public void clearAdminConstraint() {
mHelper.clearAdminConstraint();
}

@Override
public void setUserConstraint(@DpcPreferenceHelper.UserKind int userConstraints) {
mHelper.setUserConstraint(userConstraints);
}

@Override
public void clearUserConstraint() {
mHelper.clearUserConstraint();
}

@Override
public void clearNonCustomConstraints() {
mHelper.clearNonCustomConstraints();
}

@Override
public void setCustomConstraint(CharSequence constraintSummary) {
mHelper.setCustomConstraint(constraintSummary);
}

@Override
public void setCustomConstraint(@StringRes int constraintSummaryRes) {
mHelper.setCustomConstraint(getContext().getString(constraintSummaryRes));
}

@Override
public void clearCustomConstraint() {
mHelper.clearCustomConstraint();
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Copyright (C) 2016 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.afwsamples.testdpc.common.preference;

import android.content.Context;
import android.support.annotation.StringRes;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.preference.PreferenceViewHolder;
import android.util.AttributeSet;

/**
* An {@link ListPreference} which can be disabled via XML declared constraints.
*
* See {@link DpcPreferenceHelper} for details about constraints.
*/
public class DpcListPreference extends ListPreference implements DpcPreferenceBase {
private DpcPreferenceHelper mHelper;

public DpcListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
mHelper = new DpcPreferenceHelper(context, this, attrs);
}

public DpcListPreference(Context context, AttributeSet attrs, int defStyleAttr) {
this(context, attrs, defStyleAttr, 0);
}

public DpcListPreference(Context context, AttributeSet attrs) {
this(context, attrs, android.support.v7.preference.R.attr.dialogPreferenceStyle);
}

public DpcListPreference(Context context) {
this(context, null);
}

@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
mHelper.onBindViewHolder(holder);
}

@Override
protected void onAttachedToHierarchy(PreferenceManager preferenceManager) {
mHelper.onAttachedToHierarchy();
super.onAttachedToHierarchy(preferenceManager);
}

@Override
public void setEnabled(boolean enabled) {
if (enabled && !mHelper.constraintsMet()) {
return; // ignore
}
super.setEnabled(enabled);
}

@Override
public void setMinSdkVersion(int version) {
mHelper.setMinSdkVersion(version);
}

@Override
public void setAdminConstraint(@DpcPreferenceHelper.AdminKind int adminConstraint) {
mHelper.setAdminConstraint(adminConstraint);
}

@Override
public void clearAdminConstraint() {
mHelper.clearAdminConstraint();
}

@Override
public void setUserConstraint(@DpcPreferenceHelper.UserKind int userConstraints) {
mHelper.setUserConstraint(userConstraints);
}

@Override
public void clearUserConstraint() {
mHelper.clearUserConstraint();
}

@Override
public void clearNonCustomConstraints() {
mHelper.clearNonCustomConstraints();
}

@Override
public void setCustomConstraint(CharSequence constraintSummary) {
mHelper.setCustomConstraint(constraintSummary);
}

@Override
public void setCustomConstraint(@StringRes int constraintSummaryRes) {
mHelper.setCustomConstraint(getContext().getString(constraintSummaryRes));
}

@Override
public void clearCustomConstraint() {
mHelper.clearCustomConstraint();
}
}

Loading

0 comments on commit 5b8297e

Please sign in to comment.