Migrate all remaining condition cards to v2.
Bug: 112485407 Test: robotests Change-Id: I3c304c308fa6f499b4b5e21d4c5735cde7b90220
This commit is contained in:
@@ -1892,7 +1892,8 @@
|
||||
android:name=".development.DevelopmentSettingsDisabledActivity"
|
||||
android:icon="@drawable/ic_settings_development"
|
||||
android:label="@string/development_settings_title"
|
||||
android:theme="@android:style/Theme.NoDisplay">
|
||||
android:excludeFromRecents="true"
|
||||
android:theme="@style/Transparent">
|
||||
<intent-filter android:priority="-1">
|
||||
<action android:name="android.settings.APPLICATION_DEVELOPMENT_SETTINGS" />
|
||||
<action android:name="com.android.settings.APPLICATION_DEVELOPMENT_SETTINGS" />
|
||||
@@ -3069,10 +3070,12 @@
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<activity android:name=".HelpTrampoline"
|
||||
<activity
|
||||
android:name=".HelpTrampoline"
|
||||
android:exported="true"
|
||||
android:theme="@android:style/Theme.NoDisplay"
|
||||
android:theme="@style/Transparent"
|
||||
android:permission="android.permission.DUMP"
|
||||
android:excludeFromRecents="true"
|
||||
android:enabled="@bool/config_has_help" />
|
||||
|
||||
<activity android:name=".applications.autofill.AutofillPickerActivity"
|
||||
|
@@ -123,7 +123,6 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
|
||||
mSummaryLoader = new SummaryLoader(activity, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
|
||||
mConditionManager = ConditionManager.get(activity, false);
|
||||
if (com.android.settings.homepage.conditional.v2.ConditionManager.isEnabled(activity)) {
|
||||
mConditionManager = null;
|
||||
mConditionManager2 =
|
||||
|
@@ -25,6 +25,7 @@ import android.provider.Settings;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
@Deprecated
|
||||
public abstract class AbnormalRingerConditionBase extends Condition {
|
||||
|
||||
private final IntentFilter mFilter;
|
||||
@@ -45,7 +46,7 @@ public abstract class AbnormalRingerConditionBase extends Condition {
|
||||
|
||||
@Override
|
||||
public CharSequence[] getActions() {
|
||||
return new CharSequence[] {
|
||||
return new CharSequence[]{
|
||||
mManager.getContext().getText(R.string.condition_device_muted_action_turn_on_sound)
|
||||
};
|
||||
}
|
||||
|
@@ -28,6 +28,10 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.WirelessUtils;
|
||||
|
||||
/**
|
||||
* @deprecated in favor of {@link AirplaneModeConditionCard}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class AirplaneModeCondition extends Condition {
|
||||
public static String TAG = "APM_Condition";
|
||||
|
||||
|
@@ -23,6 +23,7 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Settings;
|
||||
|
||||
@Deprecated
|
||||
public class BackgroundDataCondition extends Condition {
|
||||
|
||||
public BackgroundDataCondition(ConditionManager manager) {
|
||||
|
@@ -26,6 +26,10 @@ import com.android.settings.fuelgauge.BatterySaverReceiver;
|
||||
import com.android.settings.fuelgauge.batterysaver.BatterySaverSettings;
|
||||
import com.android.settingslib.fuelgauge.BatterySaverUtils;
|
||||
|
||||
/**
|
||||
* @deprecated in favor of {@link BatterySaverConditionCard}
|
||||
*/
|
||||
@Deprecated
|
||||
public class BatterySaverCondition extends Condition implements
|
||||
BatterySaverReceiver.BatterySaverListener {
|
||||
|
||||
|
@@ -23,6 +23,7 @@ import com.android.internal.telephony.TelephonyIntents;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Settings;
|
||||
|
||||
@Deprecated
|
||||
public class CellularDataCondition extends Condition {
|
||||
|
||||
private final Receiver mReceiver;
|
||||
|
@@ -33,6 +33,10 @@ import com.android.settings.R;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.notification.ZenModeSettings;
|
||||
|
||||
/**
|
||||
* @deprecated in favor of {@link com.android.settings.homepage.conditional.v2.DndConditionCard}
|
||||
*/
|
||||
@Deprecated
|
||||
public class DndCondition extends Condition {
|
||||
|
||||
private static final String TAG = "DndCondition";
|
||||
|
@@ -33,6 +33,7 @@ import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
|
||||
@Deprecated
|
||||
public class HotspotCondition extends Condition {
|
||||
|
||||
private final WifiManager mWifiManager;
|
||||
@@ -95,7 +96,7 @@ public class HotspotCondition extends Condition {
|
||||
UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId())) {
|
||||
return new CharSequence[0];
|
||||
}
|
||||
return new CharSequence[] {context.getString(R.string.condition_turn_off)};
|
||||
return new CharSequence[]{context.getString(R.string.condition_turn_off)};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -25,6 +25,10 @@ import com.android.settings.R;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.display.NightDisplaySettings;
|
||||
|
||||
/**
|
||||
* @deprecated in favor of {@link NightDisplayConditionController}
|
||||
*/
|
||||
@Deprecated
|
||||
public final class NightDisplayCondition extends Condition
|
||||
implements ColorDisplayController.Callback {
|
||||
|
||||
|
@@ -26,6 +26,7 @@ import android.provider.Settings;
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
|
||||
@Deprecated
|
||||
public class RingerMutedCondition extends AbnormalRingerConditionBase {
|
||||
|
||||
private final NotificationManager mNotificationManager;
|
||||
|
@@ -22,6 +22,7 @@ import android.media.AudioManager;
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
|
||||
@Deprecated
|
||||
public class RingerVibrateCondition extends AbnormalRingerConditionBase {
|
||||
|
||||
RingerVibrateCondition(ConditionManager manager) {
|
||||
|
@@ -29,6 +29,7 @@ import com.android.settings.Settings;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Deprecated
|
||||
public class WorkModeCondition extends Condition {
|
||||
|
||||
private UserManager mUm;
|
||||
|
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.android.settings.homepage.conditional.v2;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.media.AudioManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class AbnormalRingerConditionController implements ConditionalCardController {
|
||||
|
||||
private static final IntentFilter FILTER =
|
||||
new IntentFilter(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION);
|
||||
|
||||
protected final AudioManager mAudioManager;
|
||||
private final Context mAppContext;
|
||||
private final ConditionManager mConditionManager;
|
||||
private final RingerModeChangeReceiver mReceiver;
|
||||
|
||||
public AbnormalRingerConditionController(Context appContext, ConditionManager manager) {
|
||||
mAppContext = appContext;
|
||||
mConditionManager = manager;
|
||||
mAudioManager = (AudioManager) appContext.getSystemService(Context.AUDIO_SERVICE);
|
||||
mReceiver = new RingerModeChangeReceiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrimaryClick(Context context) {
|
||||
context.startActivity(new Intent(Settings.ACTION_SOUND_SETTINGS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionClick() {
|
||||
mAudioManager.setRingerModeInternal(AudioManager.RINGER_MODE_NORMAL);
|
||||
mAudioManager.setStreamVolume(AudioManager.STREAM_RING, 1, 0 /* flags */);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startMonitoringStateChange() {
|
||||
mAppContext.registerReceiver(mReceiver, FILTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopMonitoringStateChange() {
|
||||
mAppContext.unregisterReceiver(mReceiver);
|
||||
}
|
||||
|
||||
class RingerModeChangeReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
if (AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION.equals(action)) {
|
||||
mConditionManager.onConditionChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.android.settings.homepage.conditional.v2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
|
||||
public class AirplaneModeConditionCard implements ConditionalCard {
|
||||
|
||||
private final Context mAppContext;
|
||||
|
||||
public AirplaneModeConditionCard(Context appContext) {
|
||||
mAppContext = appContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return AirplaneModeConditionController.ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getActionText() {
|
||||
return mAppContext.getText(R.string.condition_turn_off);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsConstant() {
|
||||
return MetricsProto.MetricsEvent.SETTINGS_CONDITION_AIRPLANE_MODE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return mAppContext.getDrawable(R.drawable.ic_airplane);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return mAppContext.getText(R.string.condition_airplane_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mAppContext.getText(R.string.condition_airplane_summary);
|
||||
}
|
||||
}
|
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.android.settings.homepage.conditional.v2;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settingslib.WirelessUtils;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class AirplaneModeConditionController implements ConditionalCardController {
|
||||
|
||||
static final int ID = Objects.hash("AirplaneModeConditionController");
|
||||
|
||||
private static final IntentFilter AIRPLANE_MODE_FILTER =
|
||||
new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
|
||||
|
||||
private final ConditionManager mConditionManager;
|
||||
private final Context mAppContext;
|
||||
private final Receiver mReceiver;
|
||||
|
||||
public AirplaneModeConditionController(Context appContext, ConditionManager conditionManager) {
|
||||
mAppContext = appContext;
|
||||
mConditionManager = conditionManager;
|
||||
mReceiver = new Receiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisplayable() {
|
||||
return WirelessUtils.isAirplaneModeOn(mAppContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrimaryClick(Context context) {
|
||||
context.startActivity(
|
||||
new Intent(Settings.ACTION_WIRELESS_SETTINGS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionClick() {
|
||||
ConnectivityManager.from(mAppContext).setAirplaneMode(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startMonitoringStateChange() {
|
||||
mAppContext.registerReceiver(mReceiver, AIRPLANE_MODE_FILTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopMonitoringStateChange() {
|
||||
mAppContext.unregisterReceiver(mReceiver);
|
||||
}
|
||||
|
||||
public class Receiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(intent.getAction())) {
|
||||
mConditionManager.onConditionChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.android.settings.homepage.conditional.v2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
|
||||
public class BackgroundDataConditionCard implements ConditionalCard {
|
||||
|
||||
private final Context mAppContext;
|
||||
|
||||
public BackgroundDataConditionCard(Context appContext) {
|
||||
mAppContext = appContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return BackgroundDataConditionController.ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getActionText() {
|
||||
return mAppContext.getText(R.string.condition_turn_off);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsConstant() {
|
||||
return MetricsProto.MetricsEvent.SETTINGS_CONDITION_BACKGROUND_DATA;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return mAppContext.getDrawable(R.drawable.ic_data_saver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return mAppContext.getText(R.string.condition_bg_data_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mAppContext.getText(R.string.condition_bg_data_summary);
|
||||
}
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.android.settings.homepage.conditional.v2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.NetworkPolicyManager;
|
||||
|
||||
import com.android.settings.Settings;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class BackgroundDataConditionController implements ConditionalCardController {
|
||||
static final int ID = Objects.hash("BackgroundDataConditionController");
|
||||
|
||||
private final Context mAppContext;
|
||||
|
||||
public BackgroundDataConditionController(Context appContext) {
|
||||
mAppContext = appContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisplayable() {
|
||||
return NetworkPolicyManager.from(mAppContext).getRestrictBackground();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrimaryClick(Context context) {
|
||||
context.startActivity(new Intent(context, Settings.DataUsageSummaryActivity.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionClick() {
|
||||
NetworkPolicyManager.from(mAppContext).setRestrictBackground(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startMonitoringStateChange() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopMonitoringStateChange() {
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.android.settings.homepage.conditional.v2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
|
||||
public class BatterySaverConditionCard implements ConditionalCard {
|
||||
|
||||
private final Context mAppContext;
|
||||
|
||||
public BatterySaverConditionCard(Context appContext) {
|
||||
mAppContext = appContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return BatterySaverConditionController.ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getActionText() {
|
||||
return mAppContext.getText(R.string.condition_turn_off);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsConstant() {
|
||||
return MetricsProto.MetricsEvent.SETTINGS_CONDITION_BATTERY_SAVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return mAppContext.getDrawable(R.drawable.ic_battery_saver_accent_24dp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return mAppContext.getText(R.string.condition_battery_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mAppContext.getText(R.string.condition_battery_summary);
|
||||
}
|
||||
}
|
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.android.settings.homepage.conditional.v2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.PowerManager;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.fuelgauge.BatterySaverReceiver;
|
||||
import com.android.settings.fuelgauge.batterysaver.BatterySaverSettings;
|
||||
import com.android.settingslib.fuelgauge.BatterySaverUtils;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class BatterySaverConditionController implements ConditionalCardController,
|
||||
BatterySaverReceiver.BatterySaverListener {
|
||||
static final int ID = Objects.hash("BatterySaverConditionController");
|
||||
|
||||
private final Context mAppContext;
|
||||
private final ConditionManager mConditionManager;
|
||||
private final BatterySaverReceiver mReceiver;
|
||||
private final PowerManager mPowerManager;
|
||||
|
||||
public BatterySaverConditionController(Context appContext, ConditionManager conditionManager) {
|
||||
mAppContext = appContext;
|
||||
mConditionManager = conditionManager;
|
||||
mPowerManager = appContext.getSystemService(PowerManager.class);
|
||||
mReceiver = new BatterySaverReceiver(appContext);
|
||||
mReceiver.setBatterySaverListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisplayable() {
|
||||
return mPowerManager.isPowerSaveMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrimaryClick(Context context) {
|
||||
new SubSettingLauncher(context)
|
||||
.setDestination(BatterySaverSettings.class.getName())
|
||||
.setSourceMetricsCategory(MetricsProto.MetricsEvent.DASHBOARD_SUMMARY)
|
||||
.setTitleRes(R.string.battery_saver)
|
||||
.launch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionClick() {
|
||||
BatterySaverUtils.setPowerSaveMode(mAppContext, false,
|
||||
/*needFirstTimeWarning*/ false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startMonitoringStateChange() {
|
||||
mReceiver.setListening(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopMonitoringStateChange() {
|
||||
mReceiver.setListening(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPowerSaveModeChanged() {
|
||||
mConditionManager.onConditionChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBatteryChanged(boolean pluggedIn) {
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.android.settings.homepage.conditional.v2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
|
||||
public class CellularDataConditionCard implements ConditionalCard {
|
||||
|
||||
private final Context mAppContext;
|
||||
|
||||
public CellularDataConditionCard(Context appContext) {
|
||||
mAppContext = appContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return CellularDataConditionController.ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getActionText() {
|
||||
return mAppContext.getText(R.string.condition_turn_on);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsConstant() {
|
||||
return MetricsProto.MetricsEvent.SETTINGS_CONDITION_CELLULAR_DATA;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return mAppContext.getDrawable(R.drawable.ic_cellular_off);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return mAppContext.getText(R.string.condition_cellular_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mAppContext.getText(R.string.condition_cellular_summary);
|
||||
}
|
||||
}
|
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.android.settings.homepage.conditional.v2;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import com.android.internal.telephony.TelephonyIntents;
|
||||
import com.android.settings.Settings;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class CellularDataConditionController implements ConditionalCardController {
|
||||
|
||||
static final int ID = Objects.hash("CellularDataConditionController");
|
||||
|
||||
private static final IntentFilter DATA_CONNECTION_FILTER =
|
||||
new IntentFilter(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
|
||||
|
||||
private final Context mAppContext;
|
||||
private final ConditionManager mConditionManager;
|
||||
private final Receiver mReceiver;
|
||||
private final TelephonyManager mTelephonyManager;
|
||||
private final ConnectivityManager mConnectivityManager;
|
||||
|
||||
public CellularDataConditionController(Context appContext, ConditionManager conditionManager) {
|
||||
mAppContext = appContext;
|
||||
mConditionManager = conditionManager;
|
||||
mReceiver = new Receiver();
|
||||
mConnectivityManager = appContext.getSystemService(
|
||||
ConnectivityManager.class);
|
||||
mTelephonyManager = appContext.getSystemService(TelephonyManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisplayable() {
|
||||
if (!mConnectivityManager.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)
|
||||
|| mTelephonyManager.getSimState() != TelephonyManager.SIM_STATE_READY) {
|
||||
return false;
|
||||
}
|
||||
return !mTelephonyManager.isDataEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrimaryClick(Context context) {
|
||||
context.startActivity(new Intent(context,
|
||||
Settings.DataUsageSummaryActivity.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionClick() {
|
||||
mTelephonyManager.setDataEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startMonitoringStateChange() {
|
||||
mAppContext.registerReceiver(mReceiver, DATA_CONNECTION_FILTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopMonitoringStateChange() {
|
||||
mAppContext.unregisterReceiver(mReceiver);
|
||||
}
|
||||
|
||||
public class Receiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED.equals(
|
||||
intent.getAction())) {
|
||||
mConditionManager.onConditionChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -141,9 +141,28 @@ public class ConditionManager {
|
||||
|
||||
private void initCandidates() {
|
||||
// Initialize controllers first.
|
||||
mCardControllers.add(new AirplaneModeConditionController(mAppContext, this /* manager */));
|
||||
mCardControllers.add(new BackgroundDataConditionController(mAppContext));
|
||||
mCardControllers.add(new BatterySaverConditionController(mAppContext, this /* manager */));
|
||||
mCardControllers.add(new CellularDataConditionController(mAppContext, this /* manager */));
|
||||
mCardControllers.add(new DndConditionCardController(mAppContext, this /* manager */));
|
||||
mCardControllers.add(new HotspotConditionController(mAppContext, this /* manager */));
|
||||
mCardControllers.add(new NightDisplayConditionController(mAppContext));
|
||||
mCardControllers.add(new RingerVibrateConditionController(mAppContext, this /* manager */));
|
||||
mCardControllers.add(new RingerMutedConditionController(mAppContext, this /* manager */));
|
||||
mCardControllers.add(new WorkModeConditionController(mAppContext));
|
||||
|
||||
// Initialize ui model later. UI model depends on controller.
|
||||
mCandidates.add(new AirplaneModeConditionCard(mAppContext));
|
||||
mCandidates.add(new BackgroundDataConditionCard(mAppContext));
|
||||
mCandidates.add(new BatterySaverConditionCard(mAppContext));
|
||||
mCandidates.add(new CellularDataConditionCard(mAppContext));
|
||||
mCandidates.add(new DndConditionCard(mAppContext, this /* manager */));
|
||||
mCandidates.add(new HotspotConditionCard(mAppContext, this /* manager */));
|
||||
mCandidates.add(new NightDisplayConditionCard(mAppContext));
|
||||
mCandidates.add(new RingerMutedConditionCard(mAppContext));
|
||||
mCandidates.add(new RingerVibrateConditionCard(mAppContext));
|
||||
mCandidates.add(new WorkModeConditionCard(mAppContext));
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -78,7 +78,7 @@ public class DndConditionCardController implements ConditionalCardController {
|
||||
public void onPrimaryClick(Context context) {
|
||||
new SubSettingLauncher(context)
|
||||
.setDestination(ZenModeSettings.class.getName())
|
||||
.setSourceMetricsCategory(MetricsProto.MetricsEvent.DASHBOARD_SUMMARY)
|
||||
.setSourceMetricsCategory(MetricsProto.MetricsEvent.SETTINGS_HOMEPAGE)
|
||||
.setTitleRes(R.string.zen_mode_settings_title)
|
||||
.launch();
|
||||
}
|
||||
|
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.android.settings.homepage.conditional.v2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
|
||||
public class HotspotConditionCard implements ConditionalCard {
|
||||
|
||||
private final Context mAppContext;
|
||||
private final ConditionManager mConditionManager;
|
||||
|
||||
public HotspotConditionCard(Context appContext, ConditionManager manager) {
|
||||
mAppContext = appContext;
|
||||
mConditionManager = manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return HotspotConditionController.ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getActionText() {
|
||||
if (RestrictedLockUtils.hasBaseUserRestriction(mAppContext,
|
||||
UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId())) {
|
||||
return null;
|
||||
}
|
||||
return mAppContext.getText(R.string.condition_turn_off);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsConstant() {
|
||||
return MetricsProto.MetricsEvent.SETTINGS_CONDITION_HOTSPOT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return mAppContext.getDrawable(R.drawable.ic_hotspot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return mAppContext.getText(R.string.condition_hotspot_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
final HotspotConditionController controller = mConditionManager.getController(getId());
|
||||
return controller.getSummary();
|
||||
}
|
||||
}
|
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.android.settings.homepage.conditional.v2;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TetherSettings;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class HotspotConditionController implements ConditionalCardController {
|
||||
static final int ID = Objects.hash("HotspotConditionController");
|
||||
|
||||
private static final IntentFilter WIFI_AP_STATE_FILTER =
|
||||
new IntentFilter(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
|
||||
|
||||
private final Context mAppContext;
|
||||
private final ConditionManager mConditionManager;
|
||||
private final WifiManager mWifiManager;
|
||||
private final Receiver mReceiver;
|
||||
|
||||
|
||||
public HotspotConditionController(Context appContext, ConditionManager conditionManager) {
|
||||
mAppContext = appContext;
|
||||
mConditionManager = conditionManager;
|
||||
mWifiManager = appContext.getSystemService(WifiManager.class);
|
||||
mReceiver = new Receiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisplayable() {
|
||||
return mWifiManager.isWifiApEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrimaryClick(Context context) {
|
||||
new SubSettingLauncher(context)
|
||||
.setDestination(TetherSettings.class.getName())
|
||||
.setSourceMetricsCategory(MetricsProto.MetricsEvent.DASHBOARD_SUMMARY)
|
||||
.setTitleRes(R.string.tether_settings_title_all)
|
||||
.launch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionClick() {
|
||||
final RestrictedLockUtils.EnforcedAdmin admin =
|
||||
RestrictedLockUtils.checkIfRestrictionEnforced(
|
||||
mAppContext, UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId());
|
||||
if (admin != null) {
|
||||
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(mAppContext, admin);
|
||||
} else {
|
||||
ConnectivityManager cm = (ConnectivityManager) mAppContext.getSystemService(
|
||||
Context.CONNECTIVITY_SERVICE);
|
||||
cm.stopTethering(ConnectivityManager.TETHERING_WIFI);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startMonitoringStateChange() {
|
||||
mAppContext.registerReceiver(mReceiver, WIFI_AP_STATE_FILTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopMonitoringStateChange() {
|
||||
mAppContext.unregisterReceiver(mReceiver);
|
||||
}
|
||||
|
||||
public CharSequence getSummary() {
|
||||
return mAppContext.getString(R.string.condition_hotspot_summary, getSsid());
|
||||
}
|
||||
|
||||
private CharSequence getSsid() {
|
||||
WifiConfiguration wifiConfig = mWifiManager.getWifiApConfiguration();
|
||||
if (wifiConfig == null) {
|
||||
return mAppContext.getText(
|
||||
com.android.internal.R.string.wifi_tether_configure_ssid_default);
|
||||
} else {
|
||||
return wifiConfig.SSID;
|
||||
}
|
||||
}
|
||||
|
||||
public class Receiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (WifiManager.WIFI_AP_STATE_CHANGED_ACTION.equals(intent.getAction())) {
|
||||
mConditionManager.onConditionChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.android.settings.homepage.conditional.v2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
|
||||
public class NightDisplayConditionCard implements ConditionalCard {
|
||||
|
||||
private final Context mAppContext;
|
||||
|
||||
public NightDisplayConditionCard(Context appContext) {
|
||||
mAppContext = appContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return NightDisplayConditionController.ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getActionText() {
|
||||
return mAppContext.getText(R.string.condition_turn_off);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsConstant() {
|
||||
return MetricsProto.MetricsEvent.SETTINGS_CONDITION_NIGHT_DISPLAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return mAppContext.getDrawable(R.drawable.ic_settings_night_display);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return mAppContext.getText(R.string.condition_night_display_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mAppContext.getText(R.string.condition_night_display_summary);
|
||||
}
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.android.settings.homepage.conditional.v2;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.internal.app.ColorDisplayController;
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.display.NightDisplaySettings;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class NightDisplayConditionController implements ConditionalCardController,
|
||||
ColorDisplayController.Callback {
|
||||
static final int ID = Objects.hash("NightDisplayConditionController");
|
||||
|
||||
private final ColorDisplayController mController;
|
||||
|
||||
public NightDisplayConditionController(Context appContext) {
|
||||
mController = new ColorDisplayController(appContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisplayable() {
|
||||
return mController.isActivated();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrimaryClick(Context context) {
|
||||
new SubSettingLauncher(context)
|
||||
.setDestination(NightDisplaySettings.class.getName())
|
||||
.setSourceMetricsCategory(MetricsProto.MetricsEvent.SETTINGS_HOMEPAGE)
|
||||
.setTitleRes(R.string.night_display_title)
|
||||
.launch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionClick() {
|
||||
mController.setActivated(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startMonitoringStateChange() {
|
||||
mController.setListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopMonitoringStateChange() {
|
||||
mController.setListener(null);
|
||||
}
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.android.settings.homepage.conditional.v2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
|
||||
public class RingerMutedConditionCard implements ConditionalCard {
|
||||
|
||||
private final Context mAppContext;
|
||||
|
||||
public RingerMutedConditionCard(Context appContext) {
|
||||
mAppContext = appContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return RingerMutedConditionController.ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getActionText() {
|
||||
return mAppContext.getText(R.string.condition_device_muted_action_turn_on_sound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsConstant() {
|
||||
return MetricsProto.MetricsEvent.SETTINGS_CONDITION_DEVICE_MUTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return mAppContext.getDrawable(R.drawable.ic_notifications_off_24dp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return mAppContext.getText(R.string.condition_device_muted_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mAppContext.getText(R.string.condition_device_muted_summary);
|
||||
}
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.android.settings.homepage.conditional.v2;
|
||||
|
||||
import static android.content.Context.NOTIFICATION_SERVICE;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class RingerMutedConditionController extends AbnormalRingerConditionController {
|
||||
static final int ID = Objects.hash("RingerMutedConditionController");
|
||||
|
||||
private final NotificationManager mNotificationManager;
|
||||
|
||||
public RingerMutedConditionController(Context appContext, ConditionManager conditionManager) {
|
||||
super(appContext, conditionManager);
|
||||
mNotificationManager =
|
||||
(NotificationManager) appContext.getSystemService(NOTIFICATION_SERVICE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisplayable() {
|
||||
int zen = Settings.Global.ZEN_MODE_OFF;
|
||||
if (mNotificationManager != null) {
|
||||
zen = mNotificationManager.getZenMode();
|
||||
}
|
||||
final boolean zenModeEnabled = zen != Settings.Global.ZEN_MODE_OFF;
|
||||
final boolean isSilent =
|
||||
mAudioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT;
|
||||
return isSilent && !zenModeEnabled;
|
||||
}
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.android.settings.homepage.conditional.v2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
|
||||
public class RingerVibrateConditionCard implements ConditionalCard {
|
||||
|
||||
private final Context mAppContext;
|
||||
|
||||
public RingerVibrateConditionCard(Context appContext) {
|
||||
mAppContext = appContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return RingerVibrateConditionController.ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getActionText() {
|
||||
return mAppContext.getText(R.string.condition_device_muted_action_turn_on_sound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsConstant() {
|
||||
return MetricsProto.MetricsEvent.SETTINGS_CONDITION_DEVICE_VIBRATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return mAppContext.getDrawable(R.drawable.ic_volume_ringer_vibrate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return mAppContext.getText(R.string.condition_device_vibrate_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mAppContext.getText(R.string.condition_device_vibrate_summary);
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.android.settings.homepage.conditional.v2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class RingerVibrateConditionController extends AbnormalRingerConditionController {
|
||||
static final int ID = Objects.hash("RingerVibrateConditionController");
|
||||
|
||||
public RingerVibrateConditionController(Context appContext, ConditionManager conditionManager) {
|
||||
super(appContext, conditionManager);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisplayable() {
|
||||
return mAudioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_VIBRATE;
|
||||
}
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.android.settings.homepage.conditional.v2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
|
||||
public class WorkModeConditionCard implements ConditionalCard {
|
||||
|
||||
private final Context mAppContext;
|
||||
|
||||
public WorkModeConditionCard(Context appContext) {
|
||||
mAppContext = appContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return WorkModeConditionController.ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getActionText() {
|
||||
return mAppContext.getText(R.string.condition_turn_on);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsConstant() {
|
||||
return MetricsProto.MetricsEvent.SETTINGS_CONDITION_WORK_MODE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return mAppContext.getDrawable(R.drawable.ic_signal_workmode_enable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return mAppContext.getText(R.string.condition_work_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mAppContext.getText(R.string.condition_work_summary);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.android.settings.homepage.conditional.v2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.settings.Settings;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class WorkModeConditionController implements ConditionalCardController {
|
||||
|
||||
static final int ID = Objects.hash("WorkModeConditionController");
|
||||
|
||||
private final Context mAppContext;
|
||||
private final UserManager mUm;
|
||||
private UserHandle mUserHandle;
|
||||
|
||||
public WorkModeConditionController(Context appContext) {
|
||||
mAppContext = appContext;
|
||||
mUm = mAppContext.getSystemService(UserManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisplayable() {
|
||||
updateUserHandle();
|
||||
return mUserHandle != null && mUm.isQuietModeEnabled(mUserHandle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrimaryClick(Context context) {
|
||||
context.startActivity(new Intent(context,
|
||||
Settings.AccountDashboardActivity.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionClick() {
|
||||
if (mUserHandle != null) {
|
||||
mUm.requestQuietModeEnabled(false, mUserHandle);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startMonitoringStateChange() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopMonitoringStateChange() {
|
||||
|
||||
}
|
||||
|
||||
private void updateUserHandle() {
|
||||
List<UserInfo> profiles = mUm.getProfiles(UserHandle.myUserId());
|
||||
final int profilesCount = profiles.size();
|
||||
mUserHandle = null;
|
||||
for (int i = 0; i < profilesCount; i++) {
|
||||
UserInfo userInfo = profiles.get(i);
|
||||
if (userInfo.isManagedProfile()) {
|
||||
// We assume there's only one managed profile, otherwise UI needs to change.
|
||||
mUserHandle = userInfo.getUserHandle();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -14,15 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.homepage.conditional;
|
||||
package com.android.settings.homepage.conditional.v2;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.AudioManager;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
@@ -35,7 +33,7 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class AbnormalRingerConditionBaseTest {
|
||||
public class AbnormalRingerConditionControllerBaseTest {
|
||||
|
||||
@Mock
|
||||
private ConditionManager mConditionManager;
|
||||
@@ -47,53 +45,39 @@ public class AbnormalRingerConditionBaseTest {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
when(mConditionManager.getContext()).thenReturn(mContext);
|
||||
mCondition = new TestCondition(mConditionManager);
|
||||
|
||||
mCondition = new TestCondition(mContext, mConditionManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newInstance_shouldMonitorRingerStateChangeBroadcast() {
|
||||
public void startMonitor_shouldMonitorRingerStateChangeBroadcast() {
|
||||
final Intent broadcast1 = new Intent("foo.bar.action");
|
||||
final Intent broadcast2 = new Intent(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION);
|
||||
|
||||
mCondition.startMonitoringStateChange();
|
||||
|
||||
mContext.sendBroadcast(broadcast1);
|
||||
assertThat(mCondition.mRefreshCalled).isFalse();
|
||||
verify(mConditionManager, never()).onConditionChanged();
|
||||
|
||||
mContext.sendBroadcast(broadcast2);
|
||||
assertThat(mCondition.mRefreshCalled).isTrue();
|
||||
verify(mConditionManager).onConditionChanged();
|
||||
}
|
||||
|
||||
private static class TestCondition extends AbnormalRingerConditionBase {
|
||||
private boolean mRefreshCalled;
|
||||
private static class TestCondition extends AbnormalRingerConditionController {
|
||||
|
||||
TestCondition(ConditionManager manager) {
|
||||
super(manager);
|
||||
public TestCondition(Context appContext, ConditionManager conditionManager) {
|
||||
super(appContext, conditionManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshState() {
|
||||
mRefreshCalled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsConstant() {
|
||||
public long getId() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return null;
|
||||
public boolean isDisplayable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -13,13 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.settings.homepage.conditional;
|
||||
package com.android.settings.homepage.conditional.v2;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -31,30 +30,25 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class BackgroundDataConditionTest {
|
||||
@Mock
|
||||
private ConditionManager mConditionManager;
|
||||
|
||||
public class BackgroundDataConditionControllerTest {
|
||||
private Context mContext;
|
||||
private BackgroundDataConditionController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mConditionManager.getContext()).thenReturn(mContext);
|
||||
mController = new BackgroundDataConditionController(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPrimaryClick_shouldReturn2SummaryActivity() {
|
||||
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
BackgroundDataCondition backgroundDataCondition
|
||||
= new BackgroundDataCondition(mConditionManager);
|
||||
backgroundDataCondition.onPrimaryClick();
|
||||
mController.onPrimaryClick(mContext);
|
||||
verify(mContext).startActivity(argumentCaptor.capture());
|
||||
Intent intent = argumentCaptor.getValue();
|
||||
|
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.android.settings.homepage.conditional.v2;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.PowerManager;
|
||||
|
||||
import com.android.settings.fuelgauge.BatterySaverReceiver;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.shadows.ShadowPowerManager;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class BatterySaverConditionControllerTest {
|
||||
@Mock
|
||||
private ConditionManager mConditionManager;
|
||||
|
||||
private ShadowPowerManager mPowerManager;
|
||||
private Context mContext;
|
||||
private BatterySaverConditionController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mPowerManager = Shadows.shadowOf(mContext.getSystemService(PowerManager.class));
|
||||
mController = new BatterySaverConditionController(mContext, mConditionManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startMonitor_shouldRegisterReceiver() {
|
||||
mController.startMonitoringStateChange();
|
||||
|
||||
verify(mContext).registerReceiver(any(BatterySaverReceiver.class), any(IntentFilter.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stopMonitor_shouldUnregisterReceiver() {
|
||||
mController.startMonitoringStateChange();
|
||||
mController.stopMonitoringStateChange();
|
||||
|
||||
verify(mContext).unregisterReceiver(any(BatterySaverReceiver.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isDisplayable_PowerSaverOn_true() {
|
||||
mPowerManager.setIsPowerSaveMode(true);
|
||||
|
||||
assertThat(mController.isDisplayable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isDisplayable_PowerSaverOff_false() {
|
||||
mPowerManager.setIsPowerSaveMode(false);
|
||||
|
||||
assertThat(mController.isDisplayable()).isFalse();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.android.settings.homepage.conditional.v2;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.Settings;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class WorkModeConditionControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private WorkModeConditionController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mController = new WorkModeConditionController(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPrimaryClick_shouldLaunchAccountsSetting() {
|
||||
final ComponentName componentName =
|
||||
new ComponentName(mContext, Settings.AccountDashboardActivity.class);
|
||||
|
||||
mController.onPrimaryClick(mContext);
|
||||
|
||||
verify(mContext).startActivity(
|
||||
argThat(intent -> intent.getComponent().equals(componentName)));
|
||||
}
|
||||
|
||||
}
|
@@ -17,14 +17,13 @@
|
||||
package com.android.settings.wallpaper;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.WallpaperManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import com.android.settings.SubSettings;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -35,14 +34,11 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.android.controller.ActivityController;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.annotation.Resetter;
|
||||
import org.robolectric.shadows.ShadowActivity;
|
||||
import org.robolectric.shadows.ShadowPackageManager;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class WallpaperSuggestionActivityTest {
|
||||
@@ -65,20 +61,6 @@ public class WallpaperSuggestionActivityTest {
|
||||
ShadowWallpaperManager.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launch_primarySuggestionActivityDoesNotExist_shouldFallback() {
|
||||
ShadowPackageManager packageManager =
|
||||
Shadows.shadowOf(RuntimeEnvironment.application.getPackageManager());
|
||||
packageManager.removePackage("com.android.settings");
|
||||
|
||||
ShadowActivity activity = Shadows.shadowOf(mController.setup().get());
|
||||
final Intent intent = activity.getNextStartedActivity();
|
||||
|
||||
assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
|
||||
assertThat(intent.getFlags()).isEqualTo(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
|
||||
assertThat(activity.isFinishing()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wallpaperServiceEnabled_no_shouldReturnTrue() {
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
|
Reference in New Issue
Block a user