Skip to content

Commit 5b8297e

Browse files
committed
Upstream 3.0.11 source
2 parents 064b1c7 + 30a6b9f commit 5b8297e

23 files changed

+1531
-691
lines changed

app/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ext {
77
// exactly 1 digit
88
versionMinor = 0
99
// exactly 2 digits
10-
versionBuild = 9
10+
versionBuild = 11
1111
}
1212

1313
android {

app/src/main/java/com/afwsamples/testdpc/EnableProfileActivity.java

+27-11
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import android.content.pm.ApplicationInfo;
2727
import android.content.pm.PackageManager;
2828
import android.os.Bundle;
29+
import android.support.annotation.StringRes;
2930
import android.support.v4.content.LocalBroadcastManager;
3031
import android.util.Log;
3132
import android.view.View;
@@ -54,7 +55,7 @@ public class EnableProfileActivity extends Activity implements NavigationBar.Nav
5455
private Button mFinishButton;
5556
private SetupWizardLayout mSetupWizardLayout;
5657

57-
private boolean mEnableProfileNow;
58+
private CheckInState mCheckinState;
5859

5960
public static final String EXTRA_ENABLE_PROFILE_NOW = "enable_profile_now";
6061
private static final IntentFilter sIntentFilter =
@@ -64,9 +65,11 @@ public class EnableProfileActivity extends Activity implements NavigationBar.Nav
6465
@Override
6566
protected void onCreate(Bundle savedInstanceState) {
6667
super.onCreate(savedInstanceState);
67-
mEnableProfileNow = getIntent().getBooleanExtra(EXTRA_ENABLE_PROFILE_NOW, false);
68+
69+
mCheckinState = new CheckInState(this);
6870
if (savedInstanceState == null) {
69-
if (mEnableProfileNow) {
71+
if (getIntent().getBooleanExtra(EXTRA_ENABLE_PROFILE_NOW, false)) {
72+
mCheckinState.setFirstAccountState(CheckInState.FIRST_ACCOUNT_STATE_READY);
7073
ProvisioningUtil.enableProfile(this);
7174
} else {
7275
// Set up an alarm to enable profile in case we do not receive first account ready
@@ -120,8 +123,7 @@ protected void onResume() {
120123
LocalBroadcastManager.getInstance(this).registerReceiver(mCheckInStateReceiver,
121124
sIntentFilter);
122125
// In case the broadcast is sent before we register the receiver.
123-
CheckInState checkInState = new CheckInState(this);
124-
refreshUi(mEnableProfileNow || checkInState.isFirstAccountReady() /* enableFinish */);
126+
refreshUi();
125127
}
126128

127129
@Override
@@ -140,16 +142,30 @@ private boolean isAccountMigrated(String addedAccount) {
140142
return false;
141143
}
142144

143-
private void refreshUi(boolean enableFinish) {
145+
private void refreshUi() {
146+
boolean enableFinish;
147+
@StringRes int headerTextResId;
148+
switch (mCheckinState.getFirstAccountState()) {
149+
case CheckInState.FIRST_ACCOUNT_STATE_READY:
150+
enableFinish = true;
151+
headerTextResId = R.string.finish_setup;
152+
break;
153+
case CheckInState.FIRST_ACCOUNT_STATE_TIMEOUT:
154+
enableFinish = true;
155+
headerTextResId = R.string.finish_setup_account_not_ready;
156+
break;
157+
case CheckInState.FIRST_ACCOUNT_STATE_PENDING:
158+
default:
159+
enableFinish = false;
160+
headerTextResId = R.string.waiting_for_first_account_check_in;
161+
break;
162+
}
144163
if (enableFinish) {
145164
mSetupWizardLayout.hideProgressBar();
146165
} else {
147166
mSetupWizardLayout.showProgressBar();
148167
}
149-
mSetupWizardLayout.setHeaderText(
150-
(enableFinish)
151-
? R.string.finish_setup
152-
: R.string.waiting_for_first_account_check_in);
168+
mSetupWizardLayout.setHeaderText(headerTextResId);
153169
mFinishButton.setEnabled(enableFinish);
154170
}
155171

@@ -167,7 +183,7 @@ class CheckInStateReceiver extends BroadcastReceiver {
167183
@Override
168184
public void onReceive(Context context, Intent intent) {
169185
// Processed the first check-in broadcast, allow user to tap the finish button.
170-
refreshUi(true);
186+
refreshUi();
171187
}
172188
}
173189
}

app/src/main/java/com/afwsamples/testdpc/FirstAccountReadyBroadcastReceiver.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,14 @@ public void onReceive(Context context, Intent intent) {
5151
if (FIRST_ACCOUNT_READY_ACTION.equals(action) ||
5252
FIRST_ACCOUNT_READY_TIMEOUT_ACTION.equals(action)) {
5353
CheckInState checkInState = new CheckInState(context);
54-
if (!checkInState.isFirstAccountReady()) {
55-
checkInState.setFirstAccountReady();
54+
if (checkInState.getFirstAccountState() == CheckInState.FIRST_ACCOUNT_STATE_PENDING) {
55+
int nextState;
56+
if (FIRST_ACCOUNT_READY_ACTION.equals(action)) {
57+
nextState = CheckInState.FIRST_ACCOUNT_STATE_READY;
58+
} else {
59+
nextState = CheckInState.FIRST_ACCOUNT_STATE_TIMEOUT;
60+
}
61+
checkInState.setFirstAccountState(nextState);
5662
ProvisioningUtil.enableProfile(context);
5763
}
5864
// This receiver is disabled in ProvisioningUtil.enableProfile, no more code should

app/src/main/java/com/afwsamples/testdpc/common/Util.java

+12-3
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,17 @@ public static boolean isManagedProfile(Context context, ComponentName admin) {
123123
}
124124
}
125125

126-
public static void disablePreference(Preference preference, int whyResId) {
127-
preference.setEnabled(false);
128-
preference.setSummary(whyResId);
126+
@TargetApi(VERSION_CODES.M)
127+
public static boolean isPrimaryUser(Context context) {
128+
if (isBeforeM()) {
129+
// Assume only DO can be primary user. This is not perfect but the cases in which it is
130+
// wrong are uncommon and require adb to set up.
131+
final DevicePolicyManager dpm =
132+
(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
133+
return dpm.isDeviceOwnerApp(context.getPackageName());
134+
} else {
135+
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
136+
return userManager.isSystemUser();
137+
}
129138
}
130139
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* Copyright (C) 2016 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+
17+
package com.afwsamples.testdpc.common.preference;
18+
19+
import android.content.Context;
20+
import android.support.annotation.StringRes;
21+
import android.support.v7.preference.EditTextPreference;
22+
import android.support.v7.preference.PreferenceManager;
23+
import android.support.v7.preference.PreferenceViewHolder;
24+
import android.util.AttributeSet;
25+
26+
/**
27+
* An {@link EditTextPreference} which can be disabled via XML declared constraints.
28+
*
29+
* See {@link DpcPreferenceHelper} for details about constraints.
30+
*/
31+
public class DpcEditTextPreference extends EditTextPreference implements DpcPreferenceBase {
32+
private DpcPreferenceHelper mHelper;
33+
34+
public DpcEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
35+
super(context, attrs, defStyleAttr, defStyleRes);
36+
mHelper = new DpcPreferenceHelper(context, this, attrs);
37+
}
38+
39+
public DpcEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr) {
40+
this(context, attrs, defStyleAttr, 0);
41+
}
42+
43+
public DpcEditTextPreference(Context context, AttributeSet attrs) {
44+
this(context, attrs, android.support.v7.preference.R.attr.editTextPreferenceStyle);
45+
}
46+
47+
public DpcEditTextPreference(Context context) {
48+
this(context, null);
49+
}
50+
51+
@Override
52+
public void onBindViewHolder(PreferenceViewHolder holder) {
53+
super.onBindViewHolder(holder);
54+
mHelper.onBindViewHolder(holder);
55+
}
56+
57+
@Override
58+
protected void onAttachedToHierarchy(PreferenceManager preferenceManager) {
59+
mHelper.onAttachedToHierarchy();
60+
super.onAttachedToHierarchy(preferenceManager);
61+
}
62+
63+
@Override
64+
public void setEnabled(boolean enabled) {
65+
if (enabled && !mHelper.constraintsMet()) {
66+
return; // ignore
67+
}
68+
super.setEnabled(enabled);
69+
}
70+
71+
@Override
72+
public void setMinSdkVersion(int version) {
73+
mHelper.setMinSdkVersion(version);
74+
}
75+
76+
@Override
77+
public void setAdminConstraint(@DpcPreferenceHelper.AdminKind int adminConstraint) {
78+
mHelper.setAdminConstraint(adminConstraint);
79+
}
80+
81+
@Override
82+
public void clearAdminConstraint() {
83+
mHelper.clearAdminConstraint();
84+
}
85+
86+
@Override
87+
public void setUserConstraint(@DpcPreferenceHelper.UserKind int userConstraints) {
88+
mHelper.setUserConstraint(userConstraints);
89+
}
90+
91+
@Override
92+
public void clearUserConstraint() {
93+
mHelper.clearUserConstraint();
94+
}
95+
96+
@Override
97+
public void clearNonCustomConstraints() {
98+
mHelper.clearNonCustomConstraints();
99+
}
100+
101+
@Override
102+
public void setCustomConstraint(CharSequence constraintSummary) {
103+
mHelper.setCustomConstraint(constraintSummary);
104+
}
105+
106+
@Override
107+
public void setCustomConstraint(@StringRes int constraintSummaryRes) {
108+
mHelper.setCustomConstraint(getContext().getString(constraintSummaryRes));
109+
}
110+
111+
@Override
112+
public void clearCustomConstraint() {
113+
mHelper.clearCustomConstraint();
114+
}
115+
}
116+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* Copyright (C) 2016 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+
17+
package com.afwsamples.testdpc.common.preference;
18+
19+
import android.content.Context;
20+
import android.support.annotation.StringRes;
21+
import android.support.v7.preference.ListPreference;
22+
import android.support.v7.preference.PreferenceManager;
23+
import android.support.v7.preference.PreferenceViewHolder;
24+
import android.util.AttributeSet;
25+
26+
/**
27+
* An {@link ListPreference} which can be disabled via XML declared constraints.
28+
*
29+
* See {@link DpcPreferenceHelper} for details about constraints.
30+
*/
31+
public class DpcListPreference extends ListPreference implements DpcPreferenceBase {
32+
private DpcPreferenceHelper mHelper;
33+
34+
public DpcListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
35+
super(context, attrs, defStyleAttr, defStyleRes);
36+
mHelper = new DpcPreferenceHelper(context, this, attrs);
37+
}
38+
39+
public DpcListPreference(Context context, AttributeSet attrs, int defStyleAttr) {
40+
this(context, attrs, defStyleAttr, 0);
41+
}
42+
43+
public DpcListPreference(Context context, AttributeSet attrs) {
44+
this(context, attrs, android.support.v7.preference.R.attr.dialogPreferenceStyle);
45+
}
46+
47+
public DpcListPreference(Context context) {
48+
this(context, null);
49+
}
50+
51+
@Override
52+
public void onBindViewHolder(PreferenceViewHolder holder) {
53+
super.onBindViewHolder(holder);
54+
mHelper.onBindViewHolder(holder);
55+
}
56+
57+
@Override
58+
protected void onAttachedToHierarchy(PreferenceManager preferenceManager) {
59+
mHelper.onAttachedToHierarchy();
60+
super.onAttachedToHierarchy(preferenceManager);
61+
}
62+
63+
@Override
64+
public void setEnabled(boolean enabled) {
65+
if (enabled && !mHelper.constraintsMet()) {
66+
return; // ignore
67+
}
68+
super.setEnabled(enabled);
69+
}
70+
71+
@Override
72+
public void setMinSdkVersion(int version) {
73+
mHelper.setMinSdkVersion(version);
74+
}
75+
76+
@Override
77+
public void setAdminConstraint(@DpcPreferenceHelper.AdminKind int adminConstraint) {
78+
mHelper.setAdminConstraint(adminConstraint);
79+
}
80+
81+
@Override
82+
public void clearAdminConstraint() {
83+
mHelper.clearAdminConstraint();
84+
}
85+
86+
@Override
87+
public void setUserConstraint(@DpcPreferenceHelper.UserKind int userConstraints) {
88+
mHelper.setUserConstraint(userConstraints);
89+
}
90+
91+
@Override
92+
public void clearUserConstraint() {
93+
mHelper.clearUserConstraint();
94+
}
95+
96+
@Override
97+
public void clearNonCustomConstraints() {
98+
mHelper.clearNonCustomConstraints();
99+
}
100+
101+
@Override
102+
public void setCustomConstraint(CharSequence constraintSummary) {
103+
mHelper.setCustomConstraint(constraintSummary);
104+
}
105+
106+
@Override
107+
public void setCustomConstraint(@StringRes int constraintSummaryRes) {
108+
mHelper.setCustomConstraint(getContext().getString(constraintSummaryRes));
109+
}
110+
111+
@Override
112+
public void clearCustomConstraint() {
113+
mHelper.clearCustomConstraint();
114+
}
115+
}
116+

0 commit comments

Comments
 (0)