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

Commit fc2cc61b authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Add public API for EuiccService log dump" am: 44aede06 am: 8985d3a9

Change-Id: I56fc3b2e8375feaa84b7c05ec3c56d288d426a5a
parents 18ea3739 8985d3a9
Loading
Loading
Loading
Loading
+33 −1
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import android.service.euicc.IDeleteSubscriptionCallback;
import android.service.euicc.IDownloadSubscriptionCallback;
import android.service.euicc.IEraseSubscriptionsCallback;
import android.service.euicc.IEuiccService;
import android.service.euicc.IEuiccServiceDumpResultCallback;
import android.service.euicc.IGetDefaultDownloadableSubscriptionListCallback;
import android.service.euicc.IGetDownloadableSubscriptionMetadataCallback;
import android.service.euicc.IGetEidCallback;
@@ -95,7 +96,7 @@ public class EuiccConnector extends StateMachine implements ServiceConnection {
     * true or onServiceDisconnected is called (and no package change has occurred which should
     * force us to reestablish the binding).
     */
    private static final int BIND_TIMEOUT_MILLIS = 30000;
    static final int BIND_TIMEOUT_MILLIS = 30000;

    /**
     * Maximum amount of idle time to hold the binding while in {@link ConnectedState}. After this,
@@ -147,6 +148,7 @@ public class EuiccConnector extends StateMachine implements ServiceConnection {
    private static final int CMD_GET_OTA_STATUS = 111;
    private static final int CMD_START_OTA_IF_NECESSARY = 112;
    private static final int CMD_ERASE_SUBSCRIPTIONS_WITH_OPTIONS = 113;
    private static final int CMD_DUMP_EUICC_SERVICE = 114;

    private static boolean isEuiccCommand(int what) {
        return what >= CMD_GET_EID;
@@ -322,6 +324,13 @@ public class EuiccConnector extends StateMachine implements ServiceConnection {
        void onRetainSubscriptionsComplete(int result);
    }

    /** Callback class for {@link #dumpEuiccService(DumpEuiccCommandCallback)}   }*/
    @VisibleForTesting(visibility = PACKAGE)
    public interface DumpEuiccServiceCommandCallback extends BaseEuiccCommandCallback {
        /** Called when the retain command has completed (though it may have failed). */
        void onDumpEuiccServiceComplete(String logs);
    }

    private Context mContext;
    private PackageManager mPm;
    private TelephonyManager mTm;
@@ -521,6 +530,14 @@ public class EuiccConnector extends StateMachine implements ServiceConnection {
        sendMessage(CMD_RETAIN_SUBSCRIPTIONS, cardId, 0 /* arg2 */, callback);
    }

    /** Asynchronously calls the currently bound EuiccService implementation to dump its states */
    @VisibleForTesting(visibility = PACKAGE)
    public void dumpEuiccService(DumpEuiccServiceCommandCallback callback) {
        sendMessage(CMD_DUMP_EUICC_SERVICE, TelephonyManager.UNSUPPORTED_CARD_ID /* ignored */,
                0 /* arg2 */,
                callback);
    }

    /**
     * State in which no EuiccService is available.
     *
@@ -923,6 +940,20 @@ public class EuiccConnector extends StateMachine implements ServiceConnection {
                                    });
                            break;
                        }
                        case CMD_DUMP_EUICC_SERVICE: {
                            mEuiccService.dump(new IEuiccServiceDumpResultCallback.Stub() {
                                @Override
                                public void onComplete(String logs)
                                        throws RemoteException {
                                    sendMessage(CMD_COMMAND_COMPLETE, (Runnable) () -> {
                                        ((DumpEuiccServiceCommandCallback) callback)
                                                .onDumpEuiccServiceComplete(logs);
                                        onCommandEnd(callback);
                                    });
                                }
                            });
                            break;
                        }
                        default: {
                            Log.wtf(TAG, "Unimplemented eUICC command: " + message.what);
                            callback.onEuiccServiceUnavailable();
@@ -968,6 +999,7 @@ public class EuiccConnector extends StateMachine implements ServiceConnection {
            case CMD_RETAIN_SUBSCRIPTIONS:
            case CMD_GET_OTA_STATUS:
            case CMD_START_OTA_IF_NECESSARY:
            case CMD_DUMP_EUICC_SERVICE:
                return (BaseEuiccCommandCallback) message.obj;
            case CMD_GET_DOWNLOADABLE_SUBSCRIPTION_METADATA:
                return ((GetMetadataRequest) message.obj).mCallback;
+29 −1
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
 */
package com.android.internal.telephony.euicc;

import static com.android.internal.telephony.euicc.EuiccConnector.BIND_TIMEOUT_MILLIS;

import android.Manifest;
import android.Manifest.permission;
import android.annotation.Nullable;
@@ -55,6 +57,7 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

/** Backing implementation of {@link android.telephony.euicc.EuiccManager}. */
@@ -1110,12 +1113,37 @@ public class EuiccController extends IEuiccController.Stub {
    }

    @Override
    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
    public void dump(FileDescriptor fd, final PrintWriter pw, String[] args) {
        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, "Requires DUMP");
        final long token = Binder.clearCallingIdentity();
        pw.println("===== BEGIN EUICC CLINIC =====");
        try {
            pw.println("===== EUICC CONNECTOR =====");
            mConnector.dump(fd, pw, args);
            final CountDownLatch countDownLatch = new CountDownLatch(1);
            mConnector.dumpEuiccService(new EuiccConnector.DumpEuiccServiceCommandCallback() {
                @Override
                public void onDumpEuiccServiceComplete(String logs) {
                    pw.println("===== EUICC SERVICE =====");
                    pw.println(logs);
                    countDownLatch.countDown();
                }

                @Override
                public void onEuiccServiceUnavailable() {
                    pw.println("===== EUICC SERVICE UNAVAILABLE =====");
                    countDownLatch.countDown();
                }
            });

            // Wait up to 30 seconds
            if (!countDownLatch.await(BIND_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) {
                pw.println("===== EUICC SERVICE TIMEOUT =====");
            }
        } catch (InterruptedException e) {
            pw.println("===== EUICC SERVICE INTERRUPTED =====");
        } finally {
            pw.println("===== END EUICC CLINIC =====");
            Binder.restoreCallingIdentity(token);
        }
    }