1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.internal.telephony; 18 19 import android.os.Handler; 20 import android.os.Registrant; 21 import android.os.RegistrantList; 22 import android.telephony.TelephonyDisplayInfo; 23 24 import com.android.telephony.Rlog; 25 26 import java.io.FileDescriptor; 27 import java.io.PrintWriter; 28 29 /** 30 * The DisplayInfoController updates and broadcasts all changes to {@link TelephonyDisplayInfo}. 31 * It manages all the information necessary for display purposes. Clients can register for display 32 * info changes via {@link #registerForTelephonyDisplayInfoChanged} and obtain the current 33 * TelephonyDisplayInfo via {@link #getTelephonyDisplayInfo}. 34 */ 35 public class DisplayInfoController extends Handler { 36 private static final String TAG = "DisplayInfoController"; 37 private final Phone mPhone; 38 private final NetworkTypeController mNetworkTypeController; 39 private final RegistrantList mTelephonyDisplayInfoChangedRegistrants = new RegistrantList(); 40 private TelephonyDisplayInfo mTelephonyDisplayInfo; 41 DisplayInfoController(Phone phone)42 public DisplayInfoController(Phone phone) { 43 mPhone = phone; 44 mNetworkTypeController = new NetworkTypeController(phone, this); 45 mNetworkTypeController.sendMessage(NetworkTypeController.EVENT_UPDATE); 46 } 47 48 /** 49 * @return the current TelephonyDisplayInfo 50 */ getTelephonyDisplayInfo()51 public TelephonyDisplayInfo getTelephonyDisplayInfo() { 52 return mTelephonyDisplayInfo; 53 } 54 55 /** 56 * Update TelephonyDisplayInfo based on network type and override network type, received from 57 * NetworkTypeController. 58 */ updateTelephonyDisplayInfo()59 public void updateTelephonyDisplayInfo() { 60 TelephonyDisplayInfo newDisplayInfo = new TelephonyDisplayInfo( 61 mPhone.getServiceState().getDataNetworkType(), 62 mNetworkTypeController.getOverrideNetworkType()); 63 if (!newDisplayInfo.equals(mTelephonyDisplayInfo)) { 64 Rlog.d(TAG, "TelephonyDisplayInfo[" + mPhone.getPhoneId() + "] changed from " 65 + mTelephonyDisplayInfo + " to " + newDisplayInfo); 66 mTelephonyDisplayInfo = newDisplayInfo; 67 mTelephonyDisplayInfoChangedRegistrants.notifyRegistrants(); 68 mPhone.notifyDisplayInfoChanged(mTelephonyDisplayInfo); 69 } 70 } 71 72 /** 73 * Register for TelephonyDisplayInfo changed. 74 * @param h Handler to notify 75 * @param what msg.what when the message is delivered 76 * @param obj msg.obj when the message is delivered 77 */ registerForTelephonyDisplayInfoChanged(Handler h, int what, Object obj)78 public void registerForTelephonyDisplayInfoChanged(Handler h, int what, Object obj) { 79 Registrant r = new Registrant(h, what, obj); 80 mTelephonyDisplayInfoChangedRegistrants.add(r); 81 } 82 83 /** 84 * Unregister for TelephonyDisplayInfo changed. 85 * @param h Handler to notify 86 */ unregisterForTelephonyDisplayInfoChanged(Handler h)87 public void unregisterForTelephonyDisplayInfoChanged(Handler h) { 88 mTelephonyDisplayInfoChangedRegistrants.remove(h); 89 } 90 91 /** 92 * Dump the current state. 93 */ dump(FileDescriptor fd, PrintWriter pw, String[] args)94 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 95 pw.println("DisplayInfoController:"); 96 pw.println(" mPhone=" + mPhone.getPhoneName()); 97 pw.println(" mTelephonyDisplayInfo=" + mTelephonyDisplayInfo.toString()); 98 pw.flush(); 99 pw.println(" ***************************************"); 100 mNetworkTypeController.dump(fd, pw, args); 101 pw.flush(); 102 } 103 } 104