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

Commit c749610f authored by Megha Patil's avatar Megha Patil
Browse files

Adding Test API to send Memory Status Event For CTS

- Send memory status to SmsStorageMonitor
- Bug: b/255881498

Test: atest CtsTelephonyTestCases:ImsServiceTest
Change-Id: Ia108d9df2f321e8f4cd4bf2f166a3c61a80b5ac2
parent 71f0a1f4
Loading
Loading
Loading
Loading
+54 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@

package com.android.internal.telephony;

import static android.content.pm.PackageManager.PERMISSION_GRANTED;

import static com.android.internal.telephony.util.TelephonyUtils.checkDumpPermission;

import android.annotation.Nullable;
@@ -792,6 +794,58 @@ public class SmsController extends ISmsImplBase {
        return getPhone(subId).getAppSmsManager().createAppSpecificSmsToken(callingPkg, intent);
    }

    @Override
    public void setStorageMonitorMemoryStatusOverride(int subId, boolean isStorageAvailable) {
        Phone phone = getPhone(subId);
        Context context;
        if (phone != null) {
            context = phone.getContext();
        } else {
            Rlog.e(LOG_TAG, "Phone Object is Null");
            return;
        }
        // If it doesn't have modify phone state permission
        // a SecurityException will be thrown.
        if (context.checkPermission(android.Manifest
                        .permission.MODIFY_PHONE_STATE, Binder.getCallingPid(),
                        Binder.getCallingUid()) != PERMISSION_GRANTED) {
            throw new SecurityException(
                    "setStorageMonitorMemoryStatusOverride needs MODIFY_PHONE_STATE");
        }
        final long identity = Binder.clearCallingIdentity();
        try {
            phone.mSmsStorageMonitor.sendMemoryStatusOverride(isStorageAvailable);
        } finally {
            Binder.restoreCallingIdentity(identity);
        }
    }

    @Override
    public void clearStorageMonitorMemoryStatusOverride(int subId) {
        Phone phone = getPhone(subId);
        Context context;
        if (phone != null) {
            context = phone.getContext();
        } else {
            Rlog.e(LOG_TAG, "Phone Object is Null");
            return;
        }
        // If it doesn't have modify phone state permission
        // a SecurityException will be thrown.
        if (context.checkPermission(android.Manifest
                        .permission.MODIFY_PHONE_STATE, Binder.getCallingPid(),
                        Binder.getCallingUid()) != PERMISSION_GRANTED) {
            throw new SecurityException(
                    "clearStorageMonitorMemoryStatusOverride needs MODIFY_PHONE_STATE");
        }
        final long identity = Binder.clearCallingIdentity();
        try {
            phone.mSmsStorageMonitor.clearMemoryStatusOverride();
        } finally {
            Binder.restoreCallingIdentity(identity);
        }
    }

    @Override
    public int checkSmsShortCodeDestination(int subId, String callingPackage,
            String callingFeatureId, String destAddress, String countryIso) {
+30 −1
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ import com.android.telephony.Rlog;
 * dual-mode devices that require support for both 3GPP and 3GPP2 format messages.
 */
public class SmsStorageMonitor extends Handler {
    private static final String TAG = "SmsStorageMonitor";
    private static final String TAG = "SmsStorageMonitor1";

    /** Maximum number of times to retry memory status reporting */
    private static final int MAX_RETRIES = 1;
@@ -86,6 +86,10 @@ public class SmsStorageMonitor extends Handler {
    final CommandsInterface mCi;
    boolean mStorageAvailable = true;

    boolean mInitialStorageAvailableStatus = true;

    private boolean mMemoryStatusOverrideFlag = false;

    /**
     * Hold the wake lock for 5 seconds, which should be enough time for
     * any receiver(s) to grab its own wake lock.
@@ -114,6 +118,31 @@ public class SmsStorageMonitor extends Handler {
        mContext.registerReceiver(mResultReceiver, filter);
    }

    /**
     * Overriding of the Memory Status by the TestApi and send the event to Handler to test
     * the RP-SMMA feature
     * @param isStorageAvailable boolean value specifies the MemoryStatus to be
     * sent to Handler
     */
    public void sendMemoryStatusOverride(boolean isStorageAvailable) {
        if (!mMemoryStatusOverrideFlag) {
            mInitialStorageAvailableStatus = mStorageAvailable;
            mMemoryStatusOverrideFlag = true;
        }
        mStorageAvailable = isStorageAvailable;
        if (isStorageAvailable) {
            sendMessage(obtainMessage(EVENT_REPORT_MEMORY_STATUS));
        }
    }

    /**
     * reset Memory Status change made by {@link #sendMemoryStatusOverride}
     */
    public void clearMemoryStatusOverride() {
        mStorageAvailable = mInitialStorageAvailableStatus;
        mMemoryStatusOverrideFlag = false;
    }

    @VisibleForTesting
    public void setMaxRetries(int maxCount) {
        mMaxRetryCount = maxCount;