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

Commit df54491a authored by Meng Wang's avatar Meng Wang Committed by Android (Google) Code Review
Browse files

Merge "Use WapPushManager system API."

parents b07ee398 843588e4
Loading
Loading
Loading
Loading
+0 −70
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony;

/**
 * WapPushManager constant value definitions
 */
public class WapPushManagerParams {
    /**
     * Application type activity
     */
    public static final int APP_TYPE_ACTIVITY = 0;

    /**
     * Application type service
     */
    public static final int APP_TYPE_SERVICE = 1;

    /**
     * Process Message return value
     * Message is handled
     */
    public static final int MESSAGE_HANDLED = 0x1;

    /**
     * Process Message return value
     * Application ID or content type was not found in the application ID table
     */
    public static final int APP_QUERY_FAILED = 0x2;

    /**
     * Process Message return value
     * Receiver application signature check failed
     */
    public static final int SIGNATURE_NO_MATCH = 0x4;

    /**
     * Process Message return value
     * Receiver application was not found
     */
    public static final int INVALID_RECEIVER_NAME = 0x8;

    /**
     * Process Message return value
     * Unknown exception
     */
    public static final int EXCEPTION_CAUGHT = 0x10;

    /**
     * Process Message return value
     * Need further processing after WapPushManager message processing
     */
    public static final int FURTHER_PROCESSING = 0x8000;

}
+44 −119
Original line number Original line Diff line number Diff line
@@ -20,8 +20,6 @@ import static com.google.android.mms.pdu.PduHeaders.MESSAGE_TYPE_DELIVERY_IND;
import static com.google.android.mms.pdu.PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND;
import static com.google.android.mms.pdu.PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND;
import static com.google.android.mms.pdu.PduHeaders.MESSAGE_TYPE_READ_ORIG_IND;
import static com.google.android.mms.pdu.PduHeaders.MESSAGE_TYPE_READ_ORIG_IND;


import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.Activity;
import android.app.Activity;
import android.app.AppOpsManager;
import android.app.AppOpsManager;
import android.app.BroadcastOptions;
import android.app.BroadcastOptions;
@@ -32,17 +30,12 @@ import android.content.ContentValues;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.net.Uri;
import android.os.Bundle;
import android.os.Bundle;
import android.os.IBinder;
import android.os.PowerWhitelistManager;
import android.os.PowerWhitelistManager;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManager;
import android.provider.Telephony;
import android.provider.Telephony;
@@ -50,8 +43,8 @@ import android.provider.Telephony.Sms.Intents;
import android.telephony.Rlog;
import android.telephony.Rlog;
import android.telephony.SmsManager;
import android.telephony.SmsManager;
import android.telephony.SubscriptionManager;
import android.telephony.SubscriptionManager;
import android.telephony.WapPushManagerConnector;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.Log;


import com.android.internal.telephony.uicc.IccUtils;
import com.android.internal.telephony.uicc.IccUtils;


@@ -65,14 +58,13 @@ import com.google.android.mms.pdu.PduPersister;
import com.google.android.mms.pdu.ReadOrigInd;
import com.google.android.mms.pdu.ReadOrigInd;


import java.util.HashMap;
import java.util.HashMap;
import java.util.List;


/**
/**
 * WAP push handler class.
 * WAP push handler class.
 *
 *
 * @hide
 * @hide
 */
 */
public class WapPushOverSms implements ServiceConnection {
public class WapPushOverSms {
    private static final String TAG = "WAP PUSH";
    private static final String TAG = "WAP PUSH";
    private static final boolean DBG = false;
    private static final boolean DBG = false;


@@ -80,11 +72,7 @@ public class WapPushOverSms implements ServiceConnection {
    private final Context mContext;
    private final Context mContext;
    PowerWhitelistManager mPowerWhitelistManager;
    PowerWhitelistManager mPowerWhitelistManager;


    private String mWapPushManagerPackage;
    private WapPushManagerConnector mWapPushManager;

    /** Assigned from ServiceConnection callback on main threaad. */
    @UnsupportedAppUsage
    private volatile IWapPushManager mWapPushManager;


    /** Broadcast receiver that binds to WapPushManager when the user unlocks the phone for the
    /** Broadcast receiver that binds to WapPushManager when the user unlocks the phone for the
     *  first time after reboot and the credential-encrypted storage is available.
     *  first time after reboot and the credential-encrypted storage is available.
@@ -94,86 +82,29 @@ public class WapPushOverSms implements ServiceConnection {
        public void onReceive(final Context context, Intent intent) {
        public void onReceive(final Context context, Intent intent) {
            Rlog.d(TAG, "Received broadcast " + intent.getAction());
            Rlog.d(TAG, "Received broadcast " + intent.getAction());
            if (Intent.ACTION_USER_UNLOCKED.equals(intent.getAction())) {
            if (Intent.ACTION_USER_UNLOCKED.equals(intent.getAction())) {
                new BindServiceThread(mContext).start();
                new Thread(() -> bindWapPushManagerService()).start();
            }
            }
        }
        }
    };
    };


    private class BindServiceThread extends Thread {
    private void bindWapPushManagerService() {
        private final Context context;
        if (!mWapPushManager.bindToWapPushManagerService()) {

            Rlog.e(TAG, "binding for wappush manager failed");
        private BindServiceThread(Context context) {
            this.context = context;
        }

        @Override
        public void run() {
            bindWapPushManagerService(context);
        }
    }

    private void bindWapPushManagerService(Context context) {
        Intent intent = new Intent(IWapPushManager.class.getName());
        ComponentName comp = resolveSystemService(context.getPackageManager(), intent);
        intent.setComponent(comp);
        if (comp == null || !context.bindService(intent, this, Context.BIND_AUTO_CREATE)) {
            Rlog.e(TAG, "bindService() for wappush manager failed");
        } else {
        } else {
            synchronized (this) {
            if (DBG) Rlog.v(TAG, "binding for wappush manager succeeded");
                mWapPushManagerPackage = comp.getPackageName();
            }
            if (DBG) Rlog.v(TAG, "bindService() for wappush manager succeeded");
        }
        }
    }
    }


    /**
     * Special function for use by the system to resolve service
     * intents to system apps.  Throws an exception if there are
     * multiple potential matches to the Intent.  Returns null if
     * there are no matches.
     */
    private static @Nullable ComponentName resolveSystemService(@NonNull PackageManager pm,
            @NonNull Intent intent) {
        List<ResolveInfo> results = pm.queryIntentServices(
                intent, PackageManager.MATCH_SYSTEM_ONLY);
        if (results == null) {
            return null;
        }
        ComponentName comp = null;
        for (int i = 0; i < results.size(); i++) {
            ResolveInfo ri = results.get(i);
            ComponentName foundComp = new ComponentName(ri.serviceInfo.applicationInfo.packageName,
                    ri.serviceInfo.name);
            if (comp != null) {
                throw new IllegalStateException("Multiple system services handle " + intent
                    + ": " + comp + ", " + foundComp);
            }
            comp = foundComp;
        }
        return comp;
    }

    @Override
    public void onServiceConnected(ComponentName name, IBinder service) {
        mWapPushManager = IWapPushManager.Stub.asInterface(service);
        if (DBG) Rlog.v(TAG, "wappush manager connected to " + hashCode());
    }

    @Override
    public void onServiceDisconnected(ComponentName name) {
        mWapPushManager = null;
        if (DBG) Rlog.v(TAG, "wappush manager disconnected.");
    }

    public WapPushOverSms(Context context) {
    public WapPushOverSms(Context context) {
        mContext = context;
        mContext = context;
        mPowerWhitelistManager =
        mPowerWhitelistManager =
                (PowerWhitelistManager) mContext.getSystemService(Context.POWER_WHITELIST_MANAGER);
                (PowerWhitelistManager) mContext.getSystemService(Context.POWER_WHITELIST_MANAGER);
        mWapPushManager = new WapPushManagerConnector(context);


        UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
        UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);


        if (userManager.isUserUnlocked()) {
        if (userManager.isUserUnlocked()) {
            bindWapPushManagerService(mContext);
            bindWapPushManagerService();
        } else {
        } else {
            IntentFilter userFilter = new IntentFilter();
            IntentFilter userFilter = new IntentFilter();
            userFilter.addAction(Intent.ACTION_USER_UNLOCKED);
            userFilter.addAction(Intent.ACTION_USER_UNLOCKED);
@@ -182,12 +113,8 @@ public class WapPushOverSms implements ServiceConnection {
    }
    }


    public void dispose() {
    public void dispose() {
        if (mWapPushManager != null) {
        if (DBG) Rlog.v(TAG, "dispose: unbind wappush manager");
        if (DBG) Rlog.v(TAG, "dispose: unbind wappush manager");
            mContext.unbindService(this);
        mWapPushManager.unbindWapPushManagerService();
        } else {
            Rlog.e(TAG, "dispose: not bound to a wappush manager");
        }
    }
    }


    /**
    /**
@@ -374,17 +301,15 @@ public class WapPushOverSms implements ServiceConnection {
         * is not found, legacy message processing will be continued.
         * is not found, legacy message processing will be continued.
         */
         */
        if (result.wapAppId != null) {
        if (result.wapAppId != null) {
            try {
            boolean processFurther = true;
            boolean processFurther = true;
                IWapPushManager wapPushMan = mWapPushManager;


                if (wapPushMan == null) {
            String wapPushManagerPackage =
                    mWapPushManager.getConnectedWapPushManagerServicePackage();
            if (wapPushManagerPackage == null) {
                if (DBG) Rlog.w(TAG, "wap push manager not found!");
                if (DBG) Rlog.w(TAG, "wap push manager not found!");
            } else {
            } else {
                    synchronized (this) {
                mPowerWhitelistManager.whitelistAppTemporarilyForEvent(
                mPowerWhitelistManager.whitelistAppTemporarilyForEvent(
                                mWapPushManagerPackage, PowerWhitelistManager.EVENT_MMS, "mms-mgr");
                        wapPushManagerPackage, PowerWhitelistManager.EVENT_MMS, "mms-mgr");
                    }


                Intent intent = new Intent();
                Intent intent = new Intent();
                intent.putExtra("transactionId", result.transactionId);
                intent.putExtra("transactionId", result.transactionId);
@@ -397,20 +322,20 @@ public class WapPushOverSms implements ServiceConnection {
                    intent.putExtra("address", address);
                    intent.putExtra("address", address);
                }
                }


                    int procRet = wapPushMan.processMessage(
                int procRet = mWapPushManager.processMessage(
                        result.wapAppId, result.contentType, intent);
                        result.wapAppId, result.contentType, intent);
                if (DBG) Rlog.v(TAG, "procRet:" + procRet);
                if (DBG) Rlog.v(TAG, "procRet:" + procRet);
                    if ((procRet & WapPushManagerParams.MESSAGE_HANDLED) > 0
                if ((procRet & WapPushManagerConnector.RESULT_MESSAGE_HANDLED) > 0
                            && (procRet & WapPushManagerParams.FURTHER_PROCESSING) == 0) {
                        && (procRet & WapPushManagerConnector.RESULT_FURTHER_PROCESSING) == 0) {
                    processFurther = false;
                    processFurther = false;
                }
                }
                if ((procRet & WapPushManagerConnector.RESULT_EXCEPTION_CAUGHT) != 0) {
                    if (DBG) Rlog.w(TAG, "remote func failed...");
                }
            }
            }
            if (!processFurther) {
            if (!processFurther) {
                return Intents.RESULT_SMS_HANDLED;
                return Intents.RESULT_SMS_HANDLED;
            }
            }
            } catch (RemoteException e) {
                if (DBG) Rlog.w(TAG, "remote func failed...");
            }
        }
        }
        if (DBG) Rlog.v(TAG, "fall back to existing handler");
        if (DBG) Rlog.v(TAG, "fall back to existing handler");


@@ -545,12 +470,12 @@ public class WapPushOverSms implements ServiceConnection {
                    break;
                    break;
                }
                }
                default:
                default:
                    Log.e(TAG, "Received unrecognized WAP Push PDU.");
                    Rlog.e(TAG, "Received unrecognized WAP Push PDU.");
            }
            }
        } catch (MmsException e) {
        } catch (MmsException e) {
            Log.e(TAG, "Failed to save MMS WAP push data: type=" + type, e);
            Rlog.e(TAG, "Failed to save MMS WAP push data: type=" + type, e);
        } catch (RuntimeException e) {
        } catch (RuntimeException e) {
            Log.e(TAG, "Unexpected RuntimeException in persisting MMS WAP push data", e);
            Rlog.e(TAG, "Unexpected RuntimeException in persisting MMS WAP push data", e);
        }
        }


    }
    }