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

Verified Commit 6ba9bbb0 authored by Marvin W.'s avatar Marvin W. 🐿️
Browse files

Add dummy TapAndPay service

parent ee8e5427
Loading
Loading
Loading
Loading
+25 −11
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2013-2017 microG Project Team
  ~ Copyright (C) 2013-2019 microG Project Team
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
@@ -90,7 +90,9 @@

    <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST" tools:ignore="ProtectedPermissions"/>
    <uses-permission
        android:name="android.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST"
        tools:ignore="ProtectedPermissions"/>

    <uses-sdk tools:overrideLibrary="
        com.takisoft.fix.support.v7.preference,
@@ -103,11 +105,11 @@
        android.support.v7.palette"/>

    <application
        android:name="android.support.multidex.MultiDexApplication"
        android:allowBackup="false"
        android:extractNativeLibs="false"
        android:icon="@mipmap/ic_core_service_app"
        android:label="@string/gms_app_name"
        android:name="android.support.multidex.MultiDexApplication">
        android:label="@string/gms_app_name">
        <meta-data
            android:name="fake-signature"
            android:value="@string/fake_signature"/>
@@ -421,8 +423,8 @@
        <activity
            android:name="org.microg.gms.ui.SettingsActivity"
            android:icon="@mipmap/ic_microg_settings"
            android:roundIcon="@mipmap/ic_microg_settings"
            android:label="@string/gms_settings_name"
            android:roundIcon="@mipmap/ic_microg_settings"
            android:theme="@style/Theme.AppCompat.Settings.Dashboard">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
@@ -438,16 +440,23 @@
        <!-- microG Settings embedded in System Settings on SDK 23 and newer -->
        <activity-alias
            android:name="org.microg.gms.ui.SettingsActivityLink"
            android:targetActivity="org.microg.gms.ui.SettingsActivity"
            android:icon="@drawable/microg_light_color_24"
            android:label="@string/gms_settings_name"
            android:targetActivity="org.microg.gms.ui.SettingsActivity"
            android:theme="@style/Theme.AppCompat.Settings.Dashboard">
            <intent-filter>
                <action android:name="com.android.settings.action.EXTRA_SETTINGS"/>
            </intent-filter>
            <meta-data android:name="com.android.settings.category" android:value="com.android.settings.category.device"/>
            <meta-data android:name="com.android.settings.icon" android:resource="@drawable/microg_light_color_24"/>
            <meta-data android:name="com.android.settings.summary" android:resource="@string/gms_settings_summary"/>

            <meta-data
                android:name="com.android.settings.category"
                android:value="com.android.settings.category.device"/>
            <meta-data
                android:name="com.android.settings.icon"
                android:resource="@drawable/microg_light_color_24"/>
            <meta-data
                android:name="com.android.settings.summary"
                android:resource="@string/gms_settings_summary"/>
        </activity-alias>

        <activity
@@ -627,6 +636,11 @@
                <action android:name="com.google.android.gms.wallet.service.BIND"/>
            </intent-filter>
        </service>
        <service android:name="org.microg.gms.tapandpay.TapAndPayService">
            <intent-filter>
                <action android:name="com.google.android.gms.tapandpay.service.BIND"/>
            </intent-filter>
        </service>

        <service android:name="org.microg.gms.cast.CastDeviceControllerService">
            <intent-filter>
+33 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 microG Project Team
 *
 * 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 org.microg.gms.tapandpay;

import com.google.android.gms.tapandpay.internal.ITapAndPayService;
import android.os.Parcel;
import android.os.RemoteException;
import android.util.Log;

public class TapAndPayImpl extends ITapAndPayService.Stub {
    private static final String TAG = "GmsTapAndPayImpl";

    @Override
    public boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws RemoteException {
        if (super.onTransact(code, data, reply, flags)) return true;
        Log.d(TAG, "onTransact [unknown]: " + code + ", " + data + ", " + flags);
        return false;
    }
}
+38 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 microG Project Team
 *
 * 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 org.microg.gms.tapandpay;

import android.os.RemoteException;

import com.google.android.gms.common.api.CommonStatusCodes;
import com.google.android.gms.common.internal.GetServiceRequest;
import com.google.android.gms.common.internal.IGmsCallbacks;

import org.microg.gms.BaseService;
import org.microg.gms.common.GmsService;

public class TapAndPayService extends BaseService {
    public TapAndPayService() {
        super("GmsTapAndPaySvc", GmsService.TAP_AND_PAY);
    }

    @Override
    public void handleServiceRequest(IGmsCallbacks callback, GetServiceRequest request, GmsService service) throws RemoteException {
        callback.onPostInitComplete(CommonStatusCodes.SUCCESS, new TapAndPayImpl(), null);

    }
}
+85 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 microG Project Team
 *
 * 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 org.microg.gms.wearable;

import android.content.Context;
import android.net.Uri;

import com.google.android.gms.common.api.CommonStatusCodes;
import com.google.android.gms.common.data.DataHolder;
import com.google.android.gms.wearable.Node;
import com.google.android.gms.wearable.WearableStatusCodes;
import com.google.android.gms.wearable.internal.NodeParcelable;

import org.microg.gms.common.PackageUtils;

import java.util.HashSet;
import java.util.Set;

public class CapabilityManager {
    private static final Uri ROOT = Uri.parse("wear:/capabilities/");
    private final Context context;
    private final WearableImpl wearable;
    private final String packageName;

    private Set<String> capabilities = new HashSet<String>();

    public CapabilityManager(Context context, WearableImpl wearable, String packageName) {
        this.context = context;
        this.wearable = wearable;
        this.packageName = packageName;
    }

    private Uri buildCapabilityUri(String capability, boolean withAuthority) {
        Uri.Builder builder = ROOT.buildUpon();
        if (withAuthority) builder.authority(wearable.getLocalNodeId());
        builder.appendPath(packageName);
        builder.appendPath(PackageUtils.firstSignatureDigest(context, packageName));
        builder.appendPath(Uri.encode(capability));
        return builder.build();
    }

    public Set<String> getNodesForCapability(String capability) {
        DataHolder dataHolder = wearable.getDataItemsByUriAsHolder(buildCapabilityUri(capability, false), packageName);
        Set<String> nodes = new HashSet<>();
        for (int i = 0; i < dataHolder.getCount(); i++) {
            nodes.add(dataHolder.getString("host", i, 0));
        }
        dataHolder.close();
        return nodes;
    }

    public int add(String capability) {
        if (this.capabilities.contains(capability)) {
            return WearableStatusCodes.DUPLICATE_CAPABILITY;
        }
        DataItemInternal dataItem = new DataItemInternal(buildCapabilityUri(capability, true));
        DataItemRecord record = wearable.putDataItem(packageName, PackageUtils.firstSignatureDigest(context, packageName), wearable.getLocalNodeId(), dataItem);
        this.capabilities.add(capability);
        wearable.syncRecordToAll(record);
        return CommonStatusCodes.SUCCESS;
    }

    public int remove(String capability) {
        if (!this.capabilities.contains(capability)) {
            return WearableStatusCodes.UNKNOWN_CAPABILITY;
        }
        wearable.deleteDataItems(buildCapabilityUri(capability, true), packageName);
        capabilities.remove(capability);
        return CommonStatusCodes.SUCCESS;
    }
}