Merge "Capture disabled in call service of the default phone app and show notification to user." am: 89945ac957 am: da7ce35eac
Change-Id: I68154bcb4fe4e245fdbb9b78c88262cd95ad29be
diff --git a/src/com/android/server/telecom/InCallController.java b/src/com/android/server/telecom/InCallController.java
index 797a442..f3a030e 100644
--- a/src/com/android/server/telecom/InCallController.java
+++ b/src/com/android/server/telecom/InCallController.java
@@ -261,8 +261,6 @@
public InCallServiceBindingConnection(InCallServiceInfo info) {
mInCallServiceInfo = info;
- mNotificationManager =
- (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
}
@Override
@@ -325,19 +323,7 @@
mContext.unbindService(mServiceConnection);
mIsConnected = false;
if (mIsNullBinding) {
- Notification.Builder builder = new Notification.Builder(mContext,
- NotificationChannelManager.CHANNEL_ID_IN_CALL_SERVICE_CRASH);
- builder.setSmallIcon(R.drawable.ic_phone)
- .setColor(mContext.getResources().getColor(R.color.theme_color))
- .setContentTitle(
- mContext.getText(
- R.string.notification_crashedInCallService_title))
- .setStyle(new Notification.BigTextStyle()
- .bigText(mContext.getString(
- R.string.notification_crashedInCallService_body,
- packageName)));
- mNotificationManager.notify(NOTIFICATION_TAG, IN_CALL_SERVICE_NOTIFICATION_ID,
- builder.build());
+ sendCrashedInCallServiceNotification(packageName);
}
if (mCall != null) {
mCall.getAnalytics().addInCallService(
@@ -1328,7 +1314,13 @@
mCallsManager.getCurrentUserHandle().getIdentifier());
Log.d(this, "Default Dialer package: " + packageName);
- return getInCallServiceComponent(packageName, IN_CALL_SERVICE_TYPE_DIALER_UI);
+ InCallServiceInfo defaultDialerComponent = getInCallServiceComponent(packageName,
+ IN_CALL_SERVICE_TYPE_DIALER_UI);
+ if (packageName != null && defaultDialerComponent == null) {
+ // The in call service of default phone app is disabled, send notification.
+ sendCrashedInCallServiceNotification(packageName);
+ }
+ return defaultDialerComponent;
}
private InCallServiceInfo getCurrentCarModeComponent() {
@@ -1807,4 +1799,22 @@
}
}
}
+
+ private void sendCrashedInCallServiceNotification(String packageName) {
+ NotificationManager notificationManager = (NotificationManager) mContext
+ .getSystemService(Context.NOTIFICATION_SERVICE);
+ Notification.Builder builder = new Notification.Builder(mContext,
+ NotificationChannelManager.CHANNEL_ID_IN_CALL_SERVICE_CRASH);
+ builder.setSmallIcon(R.drawable.ic_phone)
+ .setColor(mContext.getResources().getColor(R.color.theme_color))
+ .setContentTitle(
+ mContext.getText(
+ R.string.notification_crashedInCallService_title))
+ .setStyle(new Notification.BigTextStyle()
+ .bigText(mContext.getString(
+ R.string.notification_crashedInCallService_body,
+ packageName)));
+ notificationManager.notify(NOTIFICATION_TAG, IN_CALL_SERVICE_NOTIFICATION_ID,
+ builder.build());
+ }
}
diff --git a/testapps/res/layout/incall_screen.xml b/testapps/res/layout/incall_screen.xml
index 414bdb8..f8f919b 100644
--- a/testapps/res/layout/incall_screen.xml
+++ b/testapps/res/layout/incall_screen.xml
@@ -131,4 +131,14 @@
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"/>
</LinearLayout>
+ <Button
+ android:id="@+id/disable_incallservice"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Disable InCallService" />
+ <Button
+ android:id="@+id/enable_incallservice"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:text="Enable InCallService" />
</LinearLayout>
diff --git a/testapps/src/com/android/server/telecom/testapps/TestInCallServiceImpl.java b/testapps/src/com/android/server/telecom/testapps/TestInCallServiceImpl.java
index fb15e1d..094f0a5 100644
--- a/testapps/src/com/android/server/telecom/testapps/TestInCallServiceImpl.java
+++ b/testapps/src/com/android/server/telecom/testapps/TestInCallServiceImpl.java
@@ -23,9 +23,6 @@
import android.telecom.Phone;
import android.util.Log;
-import java.lang.Override;
-import java.lang.String;
-
/**
* Test In-Call service implementation. Logs incoming events. Mainly used to test binding to
* multiple {@link InCallService} implementations.
diff --git a/testapps/src/com/android/server/telecom/testapps/TestInCallUI.java b/testapps/src/com/android/server/telecom/testapps/TestInCallUI.java
index edcbba1..3f3a2c8 100644
--- a/testapps/src/com/android/server/telecom/testapps/TestInCallUI.java
+++ b/testapps/src/com/android/server/telecom/testapps/TestInCallUI.java
@@ -20,6 +20,7 @@
import android.bluetooth.BluetoothDevice;
import android.content.ComponentName;
import android.content.Intent;
+import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telecom.Call;
import android.telecom.CallAudioState;
@@ -233,6 +234,20 @@
Call call = mCallList.getCall(0);
call.reject(false, null);
});
+
+ findViewById(R.id.disable_incallservice).setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ disableInCallService();
+ }
+ });
+
+ findViewById(R.id.enable_incallservice).setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ enableInCallService();
+ }
+ });
}
public void updateCallAudioState(CallAudioState cas) {
@@ -285,4 +300,26 @@
SelfManagedCallList.class.getPackage().getName(),
SelfManagedConnectionService.class.getName()), "1");
}
+
+ public void disableInCallService() {
+ ComponentName uiComponent = new ComponentName(
+ TestInCallServiceImpl.class.getPackage().getName(),
+ TestInCallServiceImpl.class.getName());
+ getPackageManager().setComponentEnabledSetting(uiComponent,
+ PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
+ boolean isEnabled = getPackageManager().getComponentEnabledSetting(uiComponent)
+ == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
+ Toast.makeText(this, "Is UI enabled? " + isEnabled, Toast.LENGTH_LONG).show();
+ }
+
+ public void enableInCallService() {
+ ComponentName uiComponent = new ComponentName(
+ TestInCallServiceImpl.class.getPackage().getName(),
+ TestInCallServiceImpl.class.getName());
+ getPackageManager().setComponentEnabledSetting(uiComponent,
+ PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0);
+ boolean isEnabled = getPackageManager().getComponentEnabledSetting(uiComponent)
+ == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
+ Toast.makeText(this, "Is UI enabled? " + isEnabled, Toast.LENGTH_LONG).show();
+ }
}