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

Commit 9e0dfdce authored by Tony Mak's avatar Tony Mak
Browse files

Support copy action in ExtServices

1. Implemented CopyCodeActivity to copy the text from the incoming intent
2. Support ConversationAction of type == "copy"

Test: 1. atest SmartActionsHelperTest
      2. Send myself a message "Authentication code: 12345", observe
         the copy action. Tap on it, observe a toast and verify that
         the code is copied

BUG: 126193140
Change-Id: I73ac3b36413fd5f632951b48910c557a22b20c52
parent a49171ea
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -3681,6 +3681,7 @@
  <java-symbol type="array" name="config_displayWhiteBalanceAmbientColorTemperatures" />
  <java-symbol type="array" name="config_displayWhiteBalanceDisplayColorTemperatures" />
  <java-symbol type="drawable" name="ic_action_open" />
  <java-symbol type="drawable" name="ic_menu_copy_material" />

  <!-- MIME types -->
  <java-symbol type="string" name="mime_type_folder" />
+0 −4
Original line number Diff line number Diff line
@@ -25,10 +25,6 @@ LOCAL_PRIVATE_PLATFORM_APIS := true

LOCAL_CERTIFICATE := platform

LOCAL_AAPT_FLAGS := --shared-lib

LOCAL_EXPORT_PACKAGE_RESOURCES := true

LOCAL_PROGUARD_FLAG_FILES := proguard.proguard

LOCAL_PRIVILEGED_MODULE := true
+4 −0
Original line number Diff line number Diff line
@@ -78,6 +78,10 @@
            </intent-filter>
        </service>

        <activity android:name=".notification.CopyCodeActivity"
                  android:exported="false"
                  android:theme="@android:style/Theme.NoDisplay"/>

        <library android:name="android.ext.services"/>
    </application>

+6 −0
Original line number Diff line number Diff line
@@ -24,4 +24,10 @@
        <item>EDIT_DISTANCE</item>
        <item>EXACT_MATCH</item>
    </string-array>

    <!-- Action chip to copy a one time code to the user's clipboard [CHAR LIMIT=NONE]-->
    <string name="copy_code_desc">Copy \u201c<xliff:g id="code" example="12345">%1$s</xliff:g>\u201c</string>
    <!-- Toast to display when text is copied to the device clipboard [CHAR LIMIT=64]-->
    <string name="code_copied_to_clipboard">Code copied</string>

</resources>
+54 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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 android.ext.services.notification;

import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Intent;
import android.ext.services.R;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;

/**
 * An activity that copies text in the Bundle.
 */
public class CopyCodeActivity extends Activity {
    private static final String TAG = "CopyCodeActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        handleIntent();
        finish();
    }

    private void handleIntent() {
        String code = getIntent().getStringExtra(Intent.EXTRA_TEXT);
        if (TextUtils.isEmpty(code)) {
            Log.w(TAG, "handleIntent: empty code");
            return;
        }
        ClipboardManager clipboardManager = getSystemService(ClipboardManager.class);
        ClipData clipData = ClipData.newPlainText(null, code);
        clipboardManager.setPrimaryClip(clipData);
        Toast.makeText(getApplicationContext(), R.string.code_copied_to_clipboard,
                Toast.LENGTH_SHORT).show();
    }
}
Loading