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

Commit fa83ab2a authored by Megha Patil's avatar Megha Patil Committed by Android (Google) Code Review
Browse files

Merge "Adding Test API to send Memory Status Event For CTS"

parents 0ec19d5f c749610f
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
@@ -44,7 +44,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;
@@ -87,6 +87,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.
@@ -115,6 +119,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;