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

Commit 974a0ffd authored by Steve Kondik's avatar Steve Kondik
Browse files

cmparts: Change how parts are launched

 * Currently we're requiring a specific action with the part name
   stored in the extras. This is a bit unwieldy and we can just
   encode the part name into the action since we only ever use
   explicit intents. It also will help us integrate search in the
   next commit without having to modify the contract in the framework.

Change-Id: I2c8fab2c9b745b86e509500b09bd000f92474c52
parent 593f29b1
Loading
Loading
Loading
Loading
+1 −10
Original line number Diff line number Diff line
@@ -49,20 +49,11 @@

        <activity android:name="PartsActivity">
            <intent-filter>
                <action android:name="org.cyanogenmod.cmparts.PART" />
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

        <service android:name="org.cyanogenmod.cmparts.PartsCatalog"
                 android:permission="cyanogenmod.permission.BIND_CORE_SERVICE"
                 android:enabled="true"
                 android:exported="true">
            <intent-filter>
                <action android:name="org.cyanogenmod.cmparts.CATALOG" />
            </intent-filter>
        </service>

        <receiver android:name="BootReceiver" android:enabled="true">
            <intent-filter android:priority="2147483647">
                <action android:name="android.intent.action.BOOT_COMPLETED" />
+19 −7
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package org.cyanogenmod.cmparts;

import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.ComponentName;
import android.content.Intent;
import android.nfc.NfcAdapter;
import android.nfc.Tag;
@@ -62,22 +63,33 @@ public class PartsActivity extends SettingsDrawerActivity implements

        setContentView(R.layout.cmparts);

        PartInfo info = null;
        String action = getIntent().getAction();
        String partExtra = getIntent().getStringExtra(PartsList.EXTRA_PART_KEY);
        ComponentName cn = getIntent().getComponent();

        PartInfo info = null;
        String partExtra = null;

        // Parts are launched by setting the action to PARTS_ACTION_PREFIX.part_key
        // and using an explcit intent to get here
        if (action != null && action.startsWith(PartsList.PARTS_ACTION_PREFIX) &&
                getClass().getName().equals(cn.getClassName())) {
            partExtra = action.substring(PartsList.PARTS_ACTION_PREFIX.length() + 1);
        }

        // Settings compatibility
        String fragmentClass = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
        String component = getIntent().getComponent().getClassName();
        Bundle initialArgs = getIntent().getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
        if (initialArgs == null) {
            initialArgs = new Bundle();
        }
        String argKey = getIntent().getStringExtra(EXTRA_FRAGMENT_ARG_KEY);
        initialArgs.putString(EXTRA_FRAGMENT_ARG_KEY, argKey);

        Log.d(TAG, "Launched with: " + getIntent().toString() + " action: " +
                getIntent().getAction() + " component: " + component +
                " part: " + partExtra + " fragment: " + fragmentClass);

        if (!PartsList.ACTION_PART.equals(action) && component == null) {
            throw new UnsupportedOperationException("Unknown action: " + getIntent().getAction());
        }

        if (fragmentClass == null) {
            if (partExtra != null) {
                // Parts mode
@@ -179,7 +191,7 @@ public class PartsActivity extends SettingsDrawerActivity implements
            }
        }

        Intent intent = new Intent(PartsList.ACTION_PART);
        Intent intent = new Intent();
        intent.putExtra(EXTRA_SHOW_FRAGMENT, fragmentClass);
        intent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
        intent.putExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, titleRes);