diff options
8 files changed, 225 insertions, 0 deletions
diff --git a/packages/SystemUI/res/layout/operator_name.xml b/packages/SystemUI/res/layout/operator_name.xml new file mode 100644 index 000000000000..c4f75e927604 --- /dev/null +++ b/packages/SystemUI/res/layout/operator_name.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + 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. +--> +<com.android.systemui.statusbar.AlphaOptimizedFrameLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/operator_name_frame" + android:layout_width="wrap_content" + android:layout_height="match_parent" + > + <com.android.systemui.statusbar.OperatorNameView + android:id="@+id/operator_name" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:maxLength="20" + android:gravity="center_vertical|start" + android:textAppearance="?android:attr/textAppearanceSmall" + android:singleLine="true" /> +</com.android.systemui.statusbar.AlphaOptimizedFrameLayout> diff --git a/packages/SystemUI/res/layout/status_bar.xml b/packages/SystemUI/res/layout/status_bar.xml index c6452c03459a..6de27acd741b 100644 --- a/packages/SystemUI/res/layout/status_bar.xml +++ b/packages/SystemUI/res/layout/status_bar.xml @@ -48,6 +48,11 @@ android:paddingEnd="8dp" android:orientation="horizontal" > + <ViewStub + android:id="@+id/operator_name" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:layout="@layout/operator_name" /> <!-- The alpha of this area is controlled from both PhoneStatusBarTransitions and PhoneStatusBar (DISABLE_NOTIFICATION_ICONS). --> diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml index 0fe81d9dfef1..f54115b0c9e2 100644 --- a/packages/SystemUI/res/values/config.xml +++ b/packages/SystemUI/res/values/config.xml @@ -301,6 +301,9 @@ <!-- Enable the default volume dialog --> <bool name="enable_volume_ui">true</bool> + <!-- Whether to show operator name in the status bar --> + <bool name="config_showOperatorNameInStatusBar">false</bool> + <!-- Duration of the full carrier network change icon animation. --> <integer name="carrier_network_change_anim_time">3000</integer> diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java index 2bb992c449b6..282a71bb96ca 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java @@ -1738,6 +1738,10 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { mFailedAttempts.delete(sCurrentUser); } + public ServiceState getServiceState(int subId) { + return mServiceStates.get(subId); + } + public int getFailedUnlockAttempts(int userId) { return mFailedAttempts.get(userId, 0); } diff --git a/packages/SystemUI/src/com/android/systemui/DemoMode.java b/packages/SystemUI/src/com/android/systemui/DemoMode.java index 11996d078bc3..5c3971571b87 100644 --- a/packages/SystemUI/src/com/android/systemui/DemoMode.java +++ b/packages/SystemUI/src/com/android/systemui/DemoMode.java @@ -37,4 +37,5 @@ public interface DemoMode { public static final String COMMAND_STATUS = "status"; public static final String COMMAND_NOTIFICATIONS = "notifications"; public static final String COMMAND_VOLUME = "volume"; + public static final String COMMAND_OPERATOR = "operator"; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/OperatorNameView.java b/packages/SystemUI/src/com/android/systemui/statusbar/OperatorNameView.java new file mode 100644 index 000000000000..5090f74d4019 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/OperatorNameView.java @@ -0,0 +1,155 @@ +/* + * 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.systemui.statusbar; + +import android.content.Context; +import android.net.ConnectivityManager; +import android.graphics.Rect; +import android.os.Bundle; +import android.provider.Settings; +import android.telephony.ServiceState; +import android.telephony.SubscriptionInfo; +import android.text.TextUtils; +import android.util.AttributeSet; +import android.widget.TextView; + +import com.android.internal.telephony.IccCardConstants.State; +import com.android.keyguard.KeyguardUpdateMonitor; +import com.android.keyguard.KeyguardUpdateMonitorCallback; +import com.android.settingslib.WirelessUtils; +import com.android.systemui.DemoMode; +import com.android.systemui.Dependency; +import com.android.systemui.statusbar.policy.DarkIconDispatcher; +import com.android.systemui.statusbar.policy.DarkIconDispatcher.DarkReceiver; +import com.android.systemui.statusbar.policy.NetworkController; +import com.android.systemui.statusbar.policy.NetworkController.IconState; +import com.android.systemui.statusbar.policy.NetworkController.SignalCallback; +import com.android.systemui.tuner.TunerService; +import com.android.systemui.tuner.TunerService.Tunable; + +import java.util.List; + +public class OperatorNameView extends TextView implements DemoMode, DarkReceiver, + SignalCallback, Tunable { + + private static final String KEY_SHOW_OPERATOR_NAME = "show_operator_name"; + + private KeyguardUpdateMonitor mKeyguardUpdateMonitor; + private boolean mDemoMode; + + private final KeyguardUpdateMonitorCallback mCallback = new KeyguardUpdateMonitorCallback() { + @Override + public void onRefreshCarrierInfo() { + updateText(); + } + }; + + public OperatorNameView(Context context) { + this(context, null); + } + + public OperatorNameView(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public OperatorNameView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext); + mKeyguardUpdateMonitor.registerCallback(mCallback); + Dependency.get(DarkIconDispatcher.class).addDarkReceiver(this); + Dependency.get(NetworkController.class).addCallback(this); + Dependency.get(TunerService.class).addTunable(this, KEY_SHOW_OPERATOR_NAME); + } + + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + mKeyguardUpdateMonitor.removeCallback(mCallback); + Dependency.get(DarkIconDispatcher.class).removeDarkReceiver(this); + Dependency.get(NetworkController.class).removeCallback(this); + Dependency.get(TunerService.class).removeTunable(this); + } + + @Override + public void onDarkChanged(Rect area, float darkIntensity, int tint) { + setTextColor(DarkIconDispatcher.getTint(area, this, tint)); + } + + @Override + public void setIsAirplaneMode(IconState icon) { + update(); + } + + @Override + public void onTuningChanged(String key, String newValue) { + update(); + } + + @Override + public void dispatchDemoCommand(String command, Bundle args) { + if (!mDemoMode && command.equals(COMMAND_ENTER)) { + mDemoMode = true; + } else if (mDemoMode && command.equals(COMMAND_EXIT)) { + mDemoMode = false; + update(); + } else if (mDemoMode && command.equals(COMMAND_OPERATOR)) { + setText(args.getString("name")); + } + } + + private void update() { + boolean showOperatorName = Dependency.get(TunerService.class) + .getValue(KEY_SHOW_OPERATOR_NAME, 1) != 0; + setVisibility(showOperatorName ? VISIBLE : GONE); + + boolean hasMobile = ConnectivityManager.from(mContext) + .isNetworkSupported(ConnectivityManager.TYPE_MOBILE); + boolean airplaneMode = WirelessUtils.isAirplaneModeOn(mContext); + if (!hasMobile || airplaneMode) { + setText(null); + setVisibility(GONE); + return; + } + + if (!mDemoMode) { + updateText(); + } + } + + private void updateText() { + CharSequence displayText = null; + List<SubscriptionInfo> subs = mKeyguardUpdateMonitor.getSubscriptionInfo(false); + final int N = subs.size(); + for (int i = 0; i < N; i++) { + int subId = subs.get(i).getSubscriptionId(); + State simState = mKeyguardUpdateMonitor.getSimState(subId); + CharSequence carrierName = subs.get(i).getCarrierName(); + if (!TextUtils.isEmpty(carrierName) && simState == State.READY) { + ServiceState ss = mKeyguardUpdateMonitor.getServiceState(subId); + if (ss != null && ss.getState() == ServiceState.STATE_IN_SERVICE) { + displayText = carrierName; + break; + } + } + } + + setText(displayText); + } +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CollapsedStatusBarFragment.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CollapsedStatusBarFragment.java index 2c3f452e8274..61f3130b9be4 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CollapsedStatusBarFragment.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CollapsedStatusBarFragment.java @@ -60,6 +60,7 @@ public class CollapsedStatusBarFragment extends Fragment implements CommandQueue private StatusBar mStatusBarComponent; private DarkIconManager mDarkIconManager; private SignalClusterView mSignalClusterView; + private View mOperatorNameFrame; private SignalCallback mSignalCallback = new SignalCallback() { @Override @@ -97,6 +98,7 @@ public class CollapsedStatusBarFragment extends Fragment implements CommandQueue // Default to showing until we know otherwise. showSystemIconArea(false); initEmergencyCryptkeeperText(); + initOperatorName(); } @Override @@ -150,8 +152,10 @@ public class CollapsedStatusBarFragment extends Fragment implements CommandQueue if ((diff1 & DISABLE_SYSTEM_INFO) != 0) { if ((state1 & DISABLE_SYSTEM_INFO) != 0) { hideSystemIconArea(animate); + hideOperatorName(animate); } else { showSystemIconArea(animate); + showOperatorName(animate); } } if ((diff1 & DISABLE_NOTIFICATION_ICONS) != 0) { @@ -207,6 +211,18 @@ public class CollapsedStatusBarFragment extends Fragment implements CommandQueue animateShow(mNotificationIconAreaInner, animate); } + public void hideOperatorName(boolean animate) { + if (mOperatorNameFrame != null) { + animateHide(mOperatorNameFrame, animate); + } + } + + public void showOperatorName(boolean animate) { + if (mOperatorNameFrame != null) { + animateShow(mOperatorNameFrame, animate); + } + } + /** * Hides a view. */ @@ -268,4 +284,11 @@ public class CollapsedStatusBarFragment extends Fragment implements CommandQueue parent.removeView(emergencyViewStub); } } + + private void initOperatorName() { + if (getResources().getBoolean(R.bool.config_showOperatorNameInStatusBar)) { + ViewStub stub = mStatusBar.findViewById(R.id.operator_name); + mOperatorNameFrame = stub.inflate(); + } + } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index afcf8ffe74f4..fa2b8e89bfb8 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -4128,6 +4128,9 @@ public class StatusBar extends SystemUI implements DemoMode, } } } + if (modeChange || command.equals(COMMAND_OPERATOR)) { + dispatchDemoCommandToView(command, args, R.id.operator_name); + } } private void dispatchDemoCommandToView(String command, Bundle args, int id) { |