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

Commit 173af445 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Update the uid value to the calling package uid" into main

parents e17e7b7d 4e64460c
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -158,7 +158,14 @@ public class CallStats extends TelecomPulledAtom {
                    : (call.isOutgoing() ? CALL_STATS__CALL_DIRECTION__DIR_OUTGOING
                    : CALL_STATS__CALL_DIRECTION__DIR_UNKNOWN);
            final int accountType = getAccountType(call.getPhoneAccountFromHandle());
            final int uid = call.getAssociatedUser().getIdentifier();
            int uid = call.getCallingPackageIdentity().mCallingPackageUid;
            try {
                uid = mContext.getPackageManager().getApplicationInfo(
                        call.getTargetPhoneAccount().getComponentName().getPackageName(), 0).uid;
            } catch (Exception e) {
                Log.i(TAG, "failed to get the uid for " + e);
            }

            log(direction, call.isExternalCall(), call.isEmergencyCall(), hasMultipleAudioDevices,
                    accountType, uid, duration);
        });
+1 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ public abstract class TelecomPulledAtom extends Handler {
    private static final String TAG = TelecomPulledAtom.class.getSimpleName();
    private static final long MIN_PULL_INTERVAL_MILLIS = 23L * 60 * 60 * 1000;
    private static final int EVENT_SAVE = 1;
    private final Context mContext;
    protected final Context mContext;
    @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
    public PulledAtoms mPulledAtoms;
    protected long mLastPulledTimestamps;
+34 −7
Original line number Diff line number Diff line
@@ -37,10 +37,13 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import android.app.StatsManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Looper;
import android.os.UserHandle;
import android.telecom.PhoneAccount;
import android.telecom.PhoneAccountHandle;
import android.util.StatsEvent;

import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -655,8 +658,19 @@ public class TelecomPulledAtomTest extends TelecomTestCase {
    @Test
    public void testCallStatsOnStartThenEnd() throws Exception {
        int duration = 1000;
        UserHandle uh = UserHandle.of(UserHandle.USER_SYSTEM);
        int fakeUid = 10010;
        PhoneAccount account = mock(PhoneAccount.class);
        Call.CallingPackageIdentity callingPackage = new Call.CallingPackageIdentity();
        PackageManager pm = mock(PackageManager.class);
        ApplicationInfo ai = new ApplicationInfo();
        ai.uid = fakeUid;
        doReturn(ai).when(pm).getApplicationInfo(any(), anyInt());
        doReturn(pm).when(mSpyContext).getPackageManager();
        Context fakeContext = spy(mContext);
        doReturn("").when(fakeContext).getPackageName();
        ComponentName cn = new ComponentName(fakeContext, this.getClass());
        PhoneAccountHandle handle = mock(PhoneAccountHandle.class);
        doReturn(cn).when(handle).getComponentName();
        Call call = mock(Call.class);
        doReturn(true).when(call).isIncoming();
        doReturn(account).when(call).getPhoneAccountFromHandle();
@@ -664,7 +678,8 @@ public class TelecomPulledAtomTest extends TelecomTestCase {
        doReturn(false).when(account).hasCapabilities(eq(PhoneAccount.CAPABILITY_SELF_MANAGED));
        doReturn(true).when(account).hasCapabilities(eq(PhoneAccount.CAPABILITY_CALL_PROVIDER));
        doReturn(true).when(account).hasCapabilities(eq(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION));
        doReturn(uh).when(call).getAssociatedUser();
        doReturn(callingPackage).when(call).getCallingPackageIdentity();
        doReturn(handle).when(call).getTargetPhoneAccount();
        CallStats callStats = spy(new CallStats(mSpyContext, mLooper));

        callStats.onCallStart(call);
@@ -675,14 +690,25 @@ public class TelecomPulledAtomTest extends TelecomTestCase {

        verify(callStats, times(1)).log(eq(CALL_STATS__CALL_DIRECTION__DIR_INCOMING),
                eq(false), eq(false), eq(false), eq(CALL_STATS__ACCOUNT_TYPE__ACCOUNT_SIM),
                eq(UserHandle.USER_SYSTEM), eq(duration));
                eq(fakeUid), eq(duration));
    }

    @Test
    public void testCallStatsOnMultipleAudioDevices() throws Exception {
        int duration = 1000;
        UserHandle uh = UserHandle.of(UserHandle.USER_SYSTEM);
        int fakeUid = 10010;
        PhoneAccount account = mock(PhoneAccount.class);
        Call.CallingPackageIdentity callingPackage = new Call.CallingPackageIdentity();
        PackageManager pm = mock(PackageManager.class);
        ApplicationInfo ai = new ApplicationInfo();
        ai.uid = fakeUid;
        doReturn(ai).when(pm).getApplicationInfo(any(), anyInt());
        doReturn(pm).when(mSpyContext).getPackageManager();
        Context fakeContext = spy(mContext);
        doReturn("").when(fakeContext).getPackageName();
        ComponentName cn = new ComponentName(fakeContext, this.getClass());
        PhoneAccountHandle handle = mock(PhoneAccountHandle.class);
        doReturn(cn).when(handle).getComponentName();
        Call call = mock(Call.class);
        doReturn(true).when(call).isIncoming();
        doReturn(account).when(call).getPhoneAccountFromHandle();
@@ -690,7 +716,8 @@ public class TelecomPulledAtomTest extends TelecomTestCase {
        doReturn(false).when(account).hasCapabilities(eq(PhoneAccount.CAPABILITY_SELF_MANAGED));
        doReturn(true).when(account).hasCapabilities(eq(PhoneAccount.CAPABILITY_CALL_PROVIDER));
        doReturn(true).when(account).hasCapabilities(eq(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION));
        doReturn(uh).when(call).getAssociatedUser();
        doReturn(callingPackage).when(call).getCallingPackageIdentity();
        doReturn(handle).when(call).getTargetPhoneAccount();
        CallStats callStats = spy(new CallStats(mSpyContext, mLooper));

        callStats.onCallStart(call);
@@ -704,7 +731,7 @@ public class TelecomPulledAtomTest extends TelecomTestCase {

        verify(callStats, times(1)).log(eq(CALL_STATS__CALL_DIRECTION__DIR_INCOMING),
                eq(false), eq(false), eq(true), eq(CALL_STATS__ACCOUNT_TYPE__ACCOUNT_SIM),
                eq(UserHandle.USER_SYSTEM), eq(duration));
                eq(fakeUid), eq(duration));
    }

    @Test