Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 89945ac9 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Capture disabled in call service of the default phone app and show notification to user."

parents 2c9562d2 898b6400
Loading
Loading
Loading
Loading
+26 −16
Original line number Diff line number Diff line
@@ -261,8 +261,6 @@ public class InCallController extends CallsManagerListenerBase {

        public InCallServiceBindingConnection(InCallServiceInfo info) {
            mInCallServiceInfo = info;
            mNotificationManager =
                    (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
        }

        @Override
@@ -325,19 +323,7 @@ public class InCallController extends CallsManagerListenerBase {
                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 @@ public class InCallController extends CallsManagerListenerBase {
                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 @@ public class InCallController extends CallsManagerListenerBase {
            }
        }
    }

    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());
    }
}
+10 −0
Original line number Diff line number Diff line
@@ -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>
+0 −3
Original line number Diff line number Diff line
@@ -23,9 +23,6 @@ import android.telecom.InCallService;
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.
+37 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.app.Activity;
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 @@ public class TestInCallUI extends Activity {
            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 @@ public class TestInCallUI extends Activity {
                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();
    }
}