Merge "Add shadow to searchbar when user scrolls vertically" into oc-mr1-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index a02d0f7..e1b4b92 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2474,7 +2474,7 @@
<category android:name="com.android.settings.SHORTCUT" />
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.DreamSettings" />
+ android:value="com.android.settings.dream.DreamSettings" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
</activity>
diff --git a/src/com/android/settings/ApnEditor.java b/src/com/android/settings/ApnEditor.java
index ba160ab..196fec8 100644
--- a/src/com/android/settings/ApnEditor.java
+++ b/src/com/android/settings/ApnEditor.java
@@ -147,7 +147,8 @@
Telephony.Carriers.ROAMING_PROTOCOL, // 20
Telephony.Carriers.MVNO_TYPE, // 21
Telephony.Carriers.MVNO_MATCH_DATA, // 22
- Telephony.Carriers.EDITED // 23
+ Telephony.Carriers.EDITED, // 23
+ Telephony.Carriers.USER_EDITABLE //24
};
private static final int ID_INDEX = 0;
@@ -173,6 +174,7 @@
private static final int MVNO_TYPE_INDEX = 21;
private static final int MVNO_MATCH_DATA_INDEX = 22;
private static final int EDITED_INDEX = 23;
+ private static final int USER_EDITABLE_INDEX = 24;
@Override
@@ -284,7 +286,8 @@
Log.d(TAG, "onCreate: EDITED " + mCursor.getInt(EDITED_INDEX));
// if it's not a USER_EDITED apn, check if it's read-only
if (mCursor.getInt(EDITED_INDEX) != Telephony.Carriers.USER_EDITED &&
- apnTypesMatch(mReadOnlyApnTypes, mCursor.getString(TYPE_INDEX))) {
+ (mCursor.getInt(USER_EDITABLE_INDEX) == 0 ||
+ apnTypesMatch(mReadOnlyApnTypes, mCursor.getString(TYPE_INDEX)))) {
Log.d(TAG, "onCreate: apnTypesMatch; read-only APN");
mReadOnlyApn = true;
disableAllFields();
diff --git a/src/com/android/settings/development/DevelopmentSettings.java b/src/com/android/settings/development/DevelopmentSettings.java
index e27c746..eaaaad8 100644
--- a/src/com/android/settings/development/DevelopmentSettings.java
+++ b/src/com/android/settings/development/DevelopmentSettings.java
@@ -630,6 +630,9 @@
return;
}
+ if (Utils.isMonkeyRunning()) {
+ return;
+ }
mSwitchBar.addOnSwitchChangeListener(this);
}
diff --git a/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java b/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java
index 483e017..a25bb53 100644
--- a/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java
@@ -117,6 +117,9 @@
if (!TextUtils.equals(preference.getKey(), KEY_BUILD_NUMBER)) {
return false;
}
+ if (Utils.isMonkeyRunning()) {
+ return false;
+ }
// Don't enable developer options for secondary users.
if (!mUm.isAdminUser()) {
mMetricsFeatureProvider.action(
diff --git a/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java b/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java
index a966beb..b944577 100644
--- a/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java
+++ b/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java
@@ -32,6 +32,7 @@
* subsystem/app type.
*/
public class BatteryHistoryPreference extends Preference {
+ private static final String TAG = "BatteryHistoryPreference";
private CharSequence mSummary;
private TextView mSummaryView;
@@ -73,6 +74,7 @@
@Override
public void onBindViewHolder(PreferenceViewHolder view) {
super.onBindViewHolder(view);
+ final long startTime = System.currentTimeMillis();
if (mBatteryInfo == null) {
return;
}
@@ -88,5 +90,6 @@
UsageView usageView = (UsageView) view.findViewById(R.id.battery_usage);
usageView.findViewById(R.id.label_group).setAlpha(.7f);
mBatteryInfo.bindHistory(usageView);
+ BatteryUtils.logRuntime(TAG, "onBindViewHolder", startTime);
}
}
diff --git a/src/com/android/settings/fuelgauge/BatteryInfo.java b/src/com/android/settings/fuelgauge/BatteryInfo.java
index 0a9cfd3..a0e56c1 100644
--- a/src/com/android/settings/fuelgauge/BatteryInfo.java
+++ b/src/com/android/settings/fuelgauge/BatteryInfo.java
@@ -136,14 +136,19 @@
public static void getBatteryInfo(final Context context, final Callback callback,
boolean shortString) {
+ final long startTime = System.currentTimeMillis();
BatteryStatsHelper statsHelper = new BatteryStatsHelper(context, true);
statsHelper.create((Bundle) null);
+ BatteryUtils.logRuntime(LOG_TAG, "time to make batteryStatsHelper", startTime);
BatteryInfo.getBatteryInfo(context, callback, statsHelper, shortString);
}
public static void getBatteryInfo(final Context context, final Callback callback,
BatteryStatsHelper statsHelper, boolean shortString) {
- getBatteryInfo(context, callback, statsHelper.getStats(), shortString);
+ final long startTime = System.currentTimeMillis();
+ BatteryStats stats = statsHelper.getStats();
+ BatteryUtils.logRuntime(LOG_TAG, "time for getStats", startTime);
+ getBatteryInfo(context, callback, stats, shortString);
}
public static void getBatteryInfo(final Context context, final Callback callback,
@@ -181,7 +186,9 @@
@Override
protected void onPostExecute(BatteryInfo batteryInfo) {
+ final long startTime = System.currentTimeMillis();
callback.onBatteryInfoLoaded(batteryInfo);
+ BatteryUtils.logRuntime(LOG_TAG, "time for callback", startTime);
}
}.execute();
}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java b/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
index f8bc71b..6b624ee 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
@@ -167,6 +167,7 @@
@Override
protected void refreshUi() {
+ final long startTime = System.currentTimeMillis();
final Context context = getContext();
if (context == null) {
return;
@@ -186,6 +187,7 @@
}
BatteryEntry.startRequestQueue();
+ BatteryUtils.logRuntime(TAG, "refreshUI", startTime);
}
@VisibleForTesting
diff --git a/src/com/android/settings/fuelgauge/PowerUsageBase.java b/src/com/android/settings/fuelgauge/PowerUsageBase.java
index 51f5f39..88edb7a 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageBase.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageBase.java
@@ -37,6 +37,7 @@
// +1 to allow ordering for PowerUsageSummary.
@VisibleForTesting
static final int MENU_STATS_REFRESH = Menu.FIRST + 1;
+ private static final String TAG = "PowerUsageBase";
protected BatteryStatsHelper mStatsHelper;
protected UserManager mUm;
@@ -89,7 +90,9 @@
protected abstract void refreshUi();
protected void updatePreference(BatteryHistoryPreference historyPref) {
+ final long startTime = System.currentTimeMillis();
historyPref.setStats(mStatsHelper);
+ BatteryUtils.logRuntime(TAG, "updatePreference", startTime);
}
@Override
diff --git a/src/com/android/settings/graph/UsageGraph.java b/src/com/android/settings/graph/UsageGraph.java
index b4c4501..5a4a9cd 100644
--- a/src/com/android/settings/graph/UsageGraph.java
+++ b/src/com/android/settings/graph/UsageGraph.java
@@ -29,15 +29,18 @@
import android.graphics.Shader.TileMode;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
+import android.util.Log;
import android.util.SparseIntArray;
import android.util.TypedValue;
import android.view.View;
+import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settingslib.R;
public class UsageGraph extends View {
private static final int PATH_DELIM = -1;
+ public static final String LOG_TAG = "UsageGraph";
private final Paint mLinePaint;
private final Paint mFillPaint;
@@ -108,10 +111,12 @@
}
void setMax(int maxX, int maxY) {
+ final long startTime = System.currentTimeMillis();
mMaxX = maxX;
mMaxY = maxY;
calculateLocalPaths();
postInvalidate();
+ BatteryUtils.logRuntime(LOG_TAG, "setMax", startTime);
}
void setDividerLoc(int height) {
@@ -133,6 +138,7 @@
private void addPathAndUpdate(SparseIntArray points, SparseIntArray paths,
SparseIntArray localPaths) {
+ final long startTime = System.currentTimeMillis();
for (int i = 0, size = points.size(); i < size; i++) {
paths.put(points.keyAt(i), points.valueAt(i));
}
@@ -140,6 +146,7 @@
paths.put(points.keyAt(points.size() - 1) + 1, PATH_DELIM);
calculateLocalPaths(paths, localPaths);
postInvalidate();
+ BatteryUtils.logRuntime(LOG_TAG, "addPathAndUpdate", startTime);
}
void setAccentColor(int color) {
@@ -151,9 +158,11 @@
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
+ final long startTime = System.currentTimeMillis();
super.onSizeChanged(w, h, oldw, oldh);
updateGradient();
calculateLocalPaths();
+ BatteryUtils.logRuntime(LOG_TAG, "onSizeChanged", startTime);
}
private void calculateLocalPaths() {
@@ -162,6 +171,7 @@
}
private void calculateLocalPaths(SparseIntArray paths, SparseIntArray localPaths) {
+ final long startTime = System.currentTimeMillis();
if (getWidth() == 0) {
return;
}
@@ -194,6 +204,7 @@
localPaths.put(lx, ly);
}
}
+ BatteryUtils.logRuntime(LOG_TAG,"calculateLocalPaths", startTime);
}
private boolean hasDiff(int x1, int x2) {
@@ -220,6 +231,7 @@
@Override
protected void onDraw(Canvas canvas) {
+ final long startTime = System.currentTimeMillis();
// Draw lines across the top, middle, and bottom.
if (mMiddleDividerLoc != 0) {
drawDivider(0, canvas, mTopDividerTint);
@@ -235,6 +247,7 @@
drawLinePath(canvas, mLocalProjectedPaths, mDottedPaint);
drawFilledPath(canvas, mLocalPaths, mFillPaint);
drawLinePath(canvas, mLocalPaths, mLinePaint);
+ BatteryUtils.logRuntime(LOG_TAG, "onDraw", startTime);
}
private void drawLinePath(Canvas canvas, SparseIntArray localPaths, Paint paint) {
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/BuildNumberPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/BuildNumberPreferenceControllerTest.java
index b504bd6..6dc7bbe 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/BuildNumberPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/BuildNumberPreferenceControllerTest.java
@@ -16,6 +16,16 @@
package com.android.settings.deviceinfo;
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Answers.RETURNS_DEEP_STUBS;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
@@ -32,8 +42,10 @@
import com.android.settings.search.DatabaseIndexingManager;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.ShadowUtils;
import com.android.settingslib.core.lifecycle.Lifecycle;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -44,18 +56,11 @@
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Answers.RETURNS_DEEP_STUBS;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+ shadows = {
+ ShadowUtils.class
+ })
public class BuildNumberPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
@@ -77,8 +82,7 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- FakeFeatureFactory.setupForTest(mContext);
- mFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
+ mFactory = FakeFeatureFactory.setupForTest(mContext);
mLifecycle = new Lifecycle();
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
mController = new BuildNumberPreferenceController(
@@ -88,6 +92,11 @@
mPreference.setKey(mController.getPreferenceKey());
}
+ @After
+ public void tearDown() {
+ ShadowUtils.reset();
+ }
+
@Test
public void displayPref_shouldAlwaysDisplay() {
mController.displayPreference(mScreen);
@@ -128,6 +137,18 @@
}
@Test
+ public void handlePrefTreeClick_isMonkeyRun_doNothing() {
+ final Context context = spy(RuntimeEnvironment.application);
+ Settings.Global.putInt(context.getContentResolver(),
+ Settings.Global.DEVICE_PROVISIONED, 1);
+ ShadowUtils.setIsUserAMonkey(true);
+ mController = new BuildNumberPreferenceController(
+ context, mActivity, mFragment, mLifecycle);
+
+ assertThat(mController.handlePreferenceTreeClick(mPreference)).isFalse();
+ }
+
+ @Test
public void handlePrefTreeClick_userHasRestriction_doNothing() {
final Context context = spy(RuntimeEnvironment.application);
Settings.Global.putInt(context.getContentResolver(),
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUtils.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUtils.java
index 208fae3..854392f 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUtils.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUtils.java
@@ -29,6 +29,7 @@
private static IFingerprintManager sFingerprintManager = null;
private static boolean sIsCarrierDemoUser;
+ private static boolean sIsUserAMonkey;
@Implementation
public static int enforceSameOwner(Context context, int userId) {
@@ -47,6 +48,7 @@
public static void reset() {
sFingerprintManager = null;
sIsCarrierDemoUser = false;
+ sIsUserAMonkey = false;
}
@Implementation
@@ -58,8 +60,22 @@
sIsCarrierDemoUser = isCarrierDemoUser;
}
+ public static void setIsUserAMonkey(boolean isUserAMonkey) {
+ sIsUserAMonkey = isUserAMonkey;
+ }
+
+
@Implementation
public static boolean isCarrierDemoUser(Context context) {
return sIsCarrierDemoUser;
}
+
+ /**
+ * Returns true if Monkey is running.
+ */
+ @Implementation
+ public static boolean isMonkeyRunning() {
+ return sIsUserAMonkey;
+
+ }
}
diff --git a/tests/unit/src/com/android/settings/dream/DreamSettingsLaunchTest.java b/tests/unit/src/com/android/settings/dream/DreamSettingsLaunchTest.java
new file mode 100644
index 0000000..497fa0a
--- /dev/null
+++ b/tests/unit/src/com/android/settings/dream/DreamSettingsLaunchTest.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2017 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.dream;
+
+import android.content.Context;
+import android.content.Intent;
+import android.provider.Settings;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+@SmallTest
+public class DreamSettingsLaunchTest {
+
+ @Test
+ public void launchFromIntent_doesNotCrash() {
+ final Context context = InstrumentationRegistry.getTargetContext();
+ Intent intent = new Intent(Settings.ACTION_DREAM_SETTINGS);
+
+ context.startActivity(intent);
+ }
+}