Remove useless folders

This commit is contained in:
Venny 2020-07-19 23:19:41 +02:00
commit 2d5e3ef742
38 changed files with 0 additions and 4178 deletions

View file

@ -1,47 +0,0 @@
/*
* Copyright 2013-2015 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.
*/
apply plugin: 'com.android.library'
String getMyVersionName() {
def stdout = new ByteArrayOutputStream()
if (rootProject.file("gradlew").exists())
exec { commandLine 'git', 'describe', '--tags', '--always', '--dirty'; standardOutput = stdout }
else // automatic build system, don't tag dirty
exec { commandLine 'git', 'describe', '--tags', '--always'; standardOutput = stdout }
return stdout.toString().trim().substring(1)
}
android {
compileSdkVersion androidCompileSdk()
buildToolsVersion "$androidBuildVersionTools"
defaultConfig {
versionName getMyVersionName()
minSdkVersion androidMinSdk()
targetSdkVersion androidTargetSdk()
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
api project(':play-services-base')
api project(':play-services-cast-api')
}

View file

@ -1,34 +0,0 @@
#
# Copyright 2013-2016 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.
#
POM_NAME=Play Services Cast Library
POM_DESCRIPTION=The Play Services Library module to access the Cast API
POM_PACKAGING=aar
POM_URL=https://github.com/microg/android_external_GmsLib
POM_SCM_URL=https://github.com/microg/android_external_GmsLib
POM_SCM_CONNECTION=scm:git@github.com:microg/android_external_GmsLib.git
POM_SCM_DEV_CONNECTION=scm:git@github.com:microg/android_external_GmsLib.git
POM_LICENCE_NAME=The Apache Software License, Version 2.0
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=mar-v-in
POM_DEVELOPER_NAME=Marvin W

View file

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2013-2017 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.
-->
<manifest package="org.microg.gms.cast"/>

View file

@ -1,223 +0,0 @@
/*
* Copyright (C) 2013-2017 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 com.google.android.gms.cast;
import android.os.Bundle;
import com.google.android.gms.common.api.Api;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.PendingResult;
import com.google.android.gms.common.api.Result;
import com.google.android.gms.common.api.Status;
import org.microg.gms.cast.CastApiBuilder;
import org.microg.gms.cast.CastApiImpl;
import org.microg.gms.common.PublicApi;
import java.io.IOException;
@PublicApi
public final class Cast {
/**
* A constant indicating that the Google Cast device is not the currently active video input.
*/
public static final int ACTIVE_INPUT_STATE_NO = 0;
/**
* A constant indicating that it is not known (and/or not possible to know) whether the Google Cast device is
* the currently active video input. Active input state can only be reported when the Google Cast device is
* connected to a TV or AVR with CEC support.
*/
public static final int ACTIVE_INPUT_STATE_UNKNOWN = -1;
/**
* A constant indicating that the Google Cast device is the currently active video input.
*/
public static final int ACTIVE_INPUT_STATE_YES = 1;
/**
* A boolean extra for the connection hint bundle passed to
* {@link GoogleApiClient.ConnectionCallbacks#onConnected(Bundle)} that indicates that the connection was
* re-established, but the receiver application that was in use at the time of the connection loss is no longer
* running on the receiver.
*/
public static final String EXTRA_APP_NO_LONGER_RUNNING = "com.google.android.gms.cast.EXTRA_APP_NO_LONGER_RUNNING";
/**
* The maximum raw message length (in bytes) that is supported by a Cast channel.
*/
public static final int MAX_MESSAGE_LENGTH = 65536;
/**
* The maximum length (in characters) of a namespace name.
*/
public static final int MAX_NAMESPACE_LENGTH = 128;
/**
* A constant indicating that the Google Cast device is not currently in standby.
*/
public static final int STANDBY_STATE_NO = 0;
/**
* A constant indicating that it is not known (and/or not possible to know) whether the Google Cast device is
* currently in standby. Standby state can only be reported when the Google Cast device is connected to a TV or
* AVR with CEC support.
*/
public static final int STANDBY_STATE_UNKNOWN = -1;
/**
* A constant indicating that the Google Cast device is currently in standby.
*/
public static final int STANDBY_STATE_YES = 1;
/**
* Token to pass to {@link GoogleApiClient.Builder#addApi(Api)} to enable the Cast features.
*/
public static final Api<CastOptions> API = new Api<CastOptions>(new CastApiBuilder());
/**
* An implementation of the CastApi interface. The interface is used to interact with a cast device.
*/
public static final Cast.CastApi CastApi = new CastApiImpl();
private Cast() {
}
public interface ApplicationConnectionResult extends Result {
ApplicationMetadata getApplicationMetadata();
String getApplicationStatus();
String getSessionId();
boolean getWasLaunched();
}
public interface CastApi {
int getActiveInputState(GoogleApiClient client);
ApplicationMetadata getApplicationMetadata(GoogleApiClient client);
String getApplicationStatus(GoogleApiClient client);
int getStandbyState(GoogleApiClient client);
double getVolume(GoogleApiClient client);
boolean isMute(GoogleApiClient client);
PendingResult<Cast.ApplicationConnectionResult> joinApplication(GoogleApiClient client);
PendingResult<Cast.ApplicationConnectionResult> joinApplication(GoogleApiClient client, String applicationId, String sessionId);
PendingResult<Cast.ApplicationConnectionResult> joinApplication(GoogleApiClient client, String applicationId);
PendingResult<Cast.ApplicationConnectionResult> launchApplication(GoogleApiClient client, String applicationId, LaunchOptions launchOptions);
PendingResult<Cast.ApplicationConnectionResult> launchApplication(GoogleApiClient client, String applicationId);
@Deprecated
PendingResult<Cast.ApplicationConnectionResult> launchApplication(GoogleApiClient client, String applicationId, boolean relaunchIfRunning);
PendingResult<Status> leaveApplication(GoogleApiClient client);
void removeMessageReceivedCallbacks(GoogleApiClient client, String namespace) throws IOException;
void requestStatus(GoogleApiClient client) throws IOException;
PendingResult<Status> sendMessage(GoogleApiClient client, String namespace, String message);
void setMessageReceivedCallbacks(GoogleApiClient client, String namespace, Cast.MessageReceivedCallback callbacks) throws IOException;
void setMute(GoogleApiClient client, boolean mute) throws IOException;
void setVolume(GoogleApiClient client, double volume) throws IOException;
PendingResult<Status> stopApplication(GoogleApiClient client);
PendingResult<Status> stopApplication(GoogleApiClient client, String sessionId);
}
public static class CastOptions implements Api.ApiOptions.HasOptions {
private final CastDevice castDevice;
private final Listener castListener;
private final boolean verboseLoggingEnabled;
public CastOptions(CastDevice castDevice, Listener castListener, boolean verboseLoggingEnabled) {
this.castDevice = castDevice;
this.castListener = castListener;
this.verboseLoggingEnabled = verboseLoggingEnabled;
}
@Deprecated
public static Builder builder(CastDevice castDevice, Listener castListener) {
return new Builder(castDevice, castListener);
}
public static class Builder {
private final CastDevice castDevice;
private final Listener castListener;
private boolean verboseLoggingEnabled;
public Builder(CastDevice castDevice, Listener castListener) {
this.castDevice = castDevice;
this.castListener = castListener;
}
public CastOptions build() {
return new CastOptions(castDevice, castListener, verboseLoggingEnabled);
}
public Builder setVerboseLoggingEnabled(boolean verboseLoggingEnabled) {
this.verboseLoggingEnabled = verboseLoggingEnabled;
return this;
}
}
}
public static class Listener {
public void onActiveInputStateChanged(int activeInputState) {
}
public void onApplicationDisconnected(int statusCode) {
}
public void onApplicationMetadataChanged(ApplicationMetadata applicationMetadata) {
}
public void onApplicationStatusChanged() {
}
public void onStandbyStateChanged(int standbyState) {
}
public void onVolumeChanged() {
}
}
public interface MessageReceivedCallback {
void onMessageReceived(CastDevice castDevice, String namespace, String message);
}
}

View file

@ -1,33 +0,0 @@
/*
* Copyright (C) 2013-2017 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 com.google.android.gms.cast;
import android.annotation.TargetApi;
import android.app.Presentation;
import android.content.Context;
import android.view.Display;
@TargetApi(17)
public class CastPresentation extends Presentation {
public CastPresentation(Context outerContext, Display display) {
super(outerContext, display);
}
public CastPresentation(Context outerContext, Display display, int theme) {
super(outerContext, display, theme);
}
}

View file

@ -1,76 +0,0 @@
/*
* Copyright (C) 2013-2017 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 com.google.android.gms.cast;
import android.view.Display;
import com.google.android.gms.common.api.Api;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.Result;
import com.google.android.gms.common.api.Status;
import org.microg.gms.cast.CastRemoteDisplayApiBuilder;
import org.microg.gms.cast.CastRemoteDisplayApiImpl;
import org.microg.gms.common.PublicApi;
@PublicApi
public final class CastRemoteDisplay {
/**
* Token to pass to {@link GoogleApiClient.Builder#addApi(Api)} to enable the CastRemoteDisplay features.
*/
public static final Api<CastRemoteDisplayOptions> API = new Api<CastRemoteDisplayOptions>(new CastRemoteDisplayApiBuilder());
/**
* An implementation of the CastRemoteDisplayAPI interface. The interface is used to interact with a cast device.
*/
public static final CastRemoteDisplayApi CastApi = new CastRemoteDisplayApiImpl();
private CastRemoteDisplay() {
}
public static final class CastRemoteDisplayOptions implements Api.ApiOptions.HasOptions {
private CastDevice castDevice;
private CastRemoteDisplaySessionCallbacks callbacks;
private CastRemoteDisplayOptions(CastDevice castDevice, CastRemoteDisplaySessionCallbacks callbacks) {
this.castDevice = castDevice;
this.callbacks = callbacks;
}
public static final class Builder {
private CastDevice castDevice;
private CastRemoteDisplaySessionCallbacks callbacks;
public Builder(CastDevice castDevice, CastRemoteDisplaySessionCallbacks callbacks) {
this.castDevice = castDevice;
this.callbacks = callbacks;
}
public CastRemoteDisplayOptions build() {
return new CastRemoteDisplayOptions(castDevice, callbacks);
}
}
}
public interface CastRemoteDisplaySessionCallbacks {
void onRemoteDisplayEnded(Status status);
}
public interface CastRemoteDisplaySessionResult extends Result {
Display getPresentationDisplay();
}
}

View file

@ -1,26 +0,0 @@
/*
* Copyright (C) 2013-2017 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 com.google.android.gms.cast;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.PendingResult;
public interface CastRemoteDisplayApi {
PendingResult<CastRemoteDisplay.CastRemoteDisplaySessionResult> startRemoteDisplay(GoogleApiClient apiClient, String applicationId);
PendingResult<CastRemoteDisplay.CastRemoteDisplaySessionResult> stopRemoteDisplay(GoogleApiClient apiClient);
}

View file

@ -1,28 +0,0 @@
/*
* Copyright (C) 2013-2017 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 com.google.android.gms.cast;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
public class CastRemoteDisplayLocalService extends Service {
@Override
public IBinder onBind(Intent intent) {
return null;
}
}

View file

@ -1,34 +0,0 @@
/*
* Copyright (C) 2013-2017 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.cast;
import android.content.Context;
import android.os.Looper;
import com.google.android.gms.cast.Cast;
import com.google.android.gms.common.api.AccountInfo;
import com.google.android.gms.common.api.GoogleApiClient;
import org.microg.gms.common.api.ApiBuilder;
import org.microg.gms.common.api.ApiConnection;
public class CastApiBuilder implements ApiBuilder<Cast.CastOptions>{
@Override
public ApiConnection build(Context context, Looper looper, Cast.CastOptions options, AccountInfo accountInfo, GoogleApiClient.ConnectionCallbacks callbacks, GoogleApiClient.OnConnectionFailedListener connectionFailedListener) {
return new CastClientImpl(context, options, callbacks, connectionFailedListener);
}
}

View file

@ -1,134 +0,0 @@
/*
* Copyright (C) 2013-2017 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.cast;
import com.google.android.gms.cast.ApplicationMetadata;
import com.google.android.gms.cast.Cast;
import com.google.android.gms.cast.LaunchOptions;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.PendingResult;
import com.google.android.gms.common.api.Status;
import java.io.IOException;
// TODO
public class CastApiImpl implements Cast.CastApi {
@Override
public int getActiveInputState(GoogleApiClient client) {
return 0;
}
@Override
public ApplicationMetadata getApplicationMetadata(GoogleApiClient client) {
return null;
}
@Override
public String getApplicationStatus(GoogleApiClient client) {
return null;
}
@Override
public int getStandbyState(GoogleApiClient client) {
return 0;
}
@Override
public double getVolume(GoogleApiClient client) {
return 0;
}
@Override
public boolean isMute(GoogleApiClient client) {
return false;
}
@Override
public PendingResult<Cast.ApplicationConnectionResult> joinApplication(GoogleApiClient client) {
return null;
}
@Override
public PendingResult<Cast.ApplicationConnectionResult> joinApplication(GoogleApiClient client, String applicationId, String sessionId) {
return null;
}
@Override
public PendingResult<Cast.ApplicationConnectionResult> joinApplication(GoogleApiClient client, String applicationId) {
return null;
}
@Override
public PendingResult<Cast.ApplicationConnectionResult> launchApplication(GoogleApiClient client, String applicationId, LaunchOptions launchOptions) {
return null;
}
@Override
public PendingResult<Cast.ApplicationConnectionResult> launchApplication(GoogleApiClient client, String applicationId) {
return null;
}
@Override
public PendingResult<Cast.ApplicationConnectionResult> launchApplication(GoogleApiClient client, String applicationId, boolean relaunchIfRunning) {
return null;
}
@Override
public PendingResult<Status> leaveApplication(GoogleApiClient client) {
return null;
}
@Override
public void removeMessageReceivedCallbacks(GoogleApiClient client, String namespace) throws IOException {
}
@Override
public void requestStatus(GoogleApiClient client) throws IOException {
}
@Override
public PendingResult<Status> sendMessage(GoogleApiClient client, String namespace, String message) {
return null;
}
@Override
public void setMessageReceivedCallbacks(GoogleApiClient client, String namespace, Cast.MessageReceivedCallback callbacks) throws IOException {
}
@Override
public void setMute(GoogleApiClient client, boolean mute) throws IOException {
}
@Override
public void setVolume(GoogleApiClient client, double volume) throws IOException {
}
@Override
public PendingResult<Status> stopApplication(GoogleApiClient client) {
return null;
}
@Override
public PendingResult<Status> stopApplication(GoogleApiClient client, String sessionId) {
return null;
}
}

View file

@ -1,29 +0,0 @@
/*
* Copyright (C) 2013-2017 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.cast;
import android.content.Context;
import com.google.android.gms.cast.Cast;
import com.google.android.gms.common.api.GoogleApiClient;
import org.microg.gms.common.DummyApiConnection;
public class CastClientImpl extends DummyApiConnection {
public CastClientImpl(Context context, Cast.CastOptions options, GoogleApiClient.ConnectionCallbacks callbacks, GoogleApiClient.OnConnectionFailedListener connectionFailedListener) {
}
}

View file

@ -1,35 +0,0 @@
/*
* Copyright (C) 2013-2017 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.cast;
import android.content.Context;
import android.os.Looper;
import com.google.android.gms.cast.CastRemoteDisplay;
import com.google.android.gms.common.api.AccountInfo;
import com.google.android.gms.common.api.GoogleApiClient;
import org.microg.gms.common.DummyApiConnection;
import org.microg.gms.common.api.ApiBuilder;
import org.microg.gms.common.api.ApiConnection;
public class CastRemoteDisplayApiBuilder implements ApiBuilder<CastRemoteDisplay.CastRemoteDisplayOptions> {
@Override
public ApiConnection build(Context context, Looper looper, CastRemoteDisplay.CastRemoteDisplayOptions options, AccountInfo accountInfo, GoogleApiClient.ConnectionCallbacks callbacks, GoogleApiClient.OnConnectionFailedListener connectionFailedListener) {
return new DummyApiConnection();
}
}

View file

@ -1,34 +0,0 @@
/*
* Copyright (C) 2013-2017 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.cast;
import com.google.android.gms.cast.CastRemoteDisplay;
import com.google.android.gms.cast.CastRemoteDisplayApi;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.PendingResult;
public class CastRemoteDisplayApiImpl implements CastRemoteDisplayApi {
@Override
public PendingResult<CastRemoteDisplay.CastRemoteDisplaySessionResult> startRemoteDisplay(GoogleApiClient apiClient, String applicationId) {
return null;
}
@Override
public PendingResult<CastRemoteDisplay.CastRemoteDisplaySessionResult> stopRemoteDisplay(GoogleApiClient apiClient) {
return null;
}
}

View file

@ -1,47 +0,0 @@
/*
* Copyright 2013-2015 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.
*/
apply plugin: 'com.android.library'
String getMyVersionName() {
def stdout = new ByteArrayOutputStream()
if (rootProject.file("gradlew").exists())
exec { commandLine 'git', 'describe', '--tags', '--always', '--dirty'; standardOutput = stdout }
else // automatic build system, don't tag dirty
exec { commandLine 'git', 'describe', '--tags', '--always'; standardOutput = stdout }
return stdout.toString().trim().substring(1)
}
android {
compileSdkVersion androidCompileSdk()
buildToolsVersion "$androidBuildVersionTools"
defaultConfig {
versionName getMyVersionName()
minSdkVersion androidMinSdk()
targetSdkVersion androidTargetSdk()
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
api project(':play-services-iid')
// compile project(':play-services-measurement')
}

View file

@ -1,34 +0,0 @@
#
# Copyright 2013-2016 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.
#
POM_NAME=Play Services GCM Library
POM_DESCRIPTION=The Play Services Library module to access Google Cloud Messaging
POM_PACKAGING=aar
POM_URL=https://github.com/microg/android_external_GmsLib
POM_SCM_URL=https://github.com/microg/android_external_GmsLib
POM_SCM_CONNECTION=scm:git@github.com:microg/android_external_GmsLib.git
POM_SCM_DEV_CONNECTION=scm:git@github.com:microg/android_external_GmsLib.git
POM_LICENCE_NAME=The Apache Software License, Version 2.0
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=mar-v-in
POM_DEVELOPER_NAME=Marvin W

View file

@ -1,27 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2013-2017 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.
-->
<manifest package="org.microg.gms.gcm"
xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Permissions required for GCM -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<!-- Move to play-services-measurement -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>

View file

@ -1,194 +0,0 @@
/*
* Copyright (C) 2013-2017 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 com.google.android.gms.gcm;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import org.microg.gms.common.PublicApi;
import static org.microg.gms.gcm.GcmConstants.ACTION_C2DM_RECEIVE;
import static org.microg.gms.gcm.GcmConstants.ACTION_NOTIFICATION_OPEN;
import static org.microg.gms.gcm.GcmConstants.EXTRA_ERROR;
import static org.microg.gms.gcm.GcmConstants.EXTRA_FROM;
import static org.microg.gms.gcm.GcmConstants.EXTRA_MESSAGE_ID;
import static org.microg.gms.gcm.GcmConstants.EXTRA_MESSAGE_TYPE;
import static org.microg.gms.gcm.GcmConstants.EXTRA_PENDING_INTENT;
import static org.microg.gms.gcm.GcmConstants.MESSAGE_TYPE_DELETED_MESSAGE;
import static org.microg.gms.gcm.GcmConstants.MESSAGE_TYPE_GCM;
import static org.microg.gms.gcm.GcmConstants.MESSAGE_TYPE_SEND_ERROR;
import static org.microg.gms.gcm.GcmConstants.MESSAGE_TYPE_SEND_EVENT;
/**
* Base class for communicating with Google Cloud Messaging.
* <p/>
* It also provides functionality such as automatically displaying
* <a href="https://developer.android.com/google/gcm/server.html">notifications when requested by app server</a>.
* <p/>
* Override base class methods to handle any events required by the application.
* Methods are invoked asynchronously.
* <p/>
* Include the following in the manifest:
* <pre>
* <service
* android:name=".YourGcmListenerService"
* android:exported="false" >
* <intent-filter>
* <action android:name="com.google.android.c2dm.intent.RECEIVE" />
* </intent-filter>
* </service></pre>
*/
@PublicApi
public abstract class GcmListenerService extends Service {
private static final String TAG = "GcmListenerService";
private final Object lock = new Object();
private int startId;
private int counter = 0;
public final IBinder onBind(Intent intent) {
return null;
}
/**
* Called when GCM server deletes pending messages due to exceeded
* storage limits, for example, when the device cannot be reached
* for an extended period of time.
* <p/>
* It is recommended to retrieve any missing messages directly from the
* app server.
*/
public void onDeletedMessages() {
// To be overwritten
}
/**
* Called when a message is received.
*
* @param from describes message sender.
* @param data message data as String key/value pairs.
*/
public void onMessageReceived(String from, Bundle data) {
// To be overwritten
}
/**
* Called when an upstream message has been successfully sent to the
* GCM connection server.
*
* @param msgId of the upstream message sent using
* {@link com.google.android.gms.gcm.GoogleCloudMessaging#send(java.lang.String, java.lang.String, android.os.Bundle)}.
*/
public void onMessageSent(String msgId) {
// To be overwritten
}
/**
* Called when there was an error sending an upstream message.
*
* @param msgId of the upstream message sent using
* {@link com.google.android.gms.gcm.GoogleCloudMessaging#send(java.lang.String, java.lang.String, android.os.Bundle)}.
* @param error description of the error.
*/
public void onSendError(String msgId, String error) {
// To be overwritten
}
public final int onStartCommand(final Intent intent, int flags, int startId) {
synchronized (lock) {
this.startId = startId;
this.counter++;
}
if (intent != null) {
if (ACTION_NOTIFICATION_OPEN.equals(intent.getAction())) {
handlePendingNotification(intent);
finishCounter();
GcmReceiver.completeWakefulIntent(intent);
} else if (ACTION_C2DM_RECEIVE.equals(intent.getAction())) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
handleC2dmMessage(intent);
return null;
}
}.execute();
} else {
Log.w(TAG, "Unknown intent action: " + intent.getAction());
}
return START_REDELIVER_INTENT;
} else {
finishCounter();
return START_NOT_STICKY;
}
}
private void handleC2dmMessage(Intent intent) {
try {
String messageType = intent.getStringExtra(EXTRA_MESSAGE_TYPE);
if (messageType == null || MESSAGE_TYPE_GCM.equals(messageType)) {
String from = intent.getStringExtra(EXTRA_FROM);
Bundle data = intent.getExtras();
data.remove(EXTRA_MESSAGE_TYPE);
data.remove("android.support.content.wakelockid"); // WakefulBroadcastReceiver.EXTRA_WAKE_LOCK_ID
data.remove(EXTRA_FROM);
onMessageReceived(from, data);
} else if (MESSAGE_TYPE_DELETED_MESSAGE.equals(messageType)) {
onDeletedMessages();
} else if (MESSAGE_TYPE_SEND_EVENT.equals(messageType)) {
onMessageSent(intent.getStringExtra(EXTRA_MESSAGE_ID));
} else if (MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
onSendError(intent.getStringExtra(EXTRA_MESSAGE_ID), intent.getStringExtra(EXTRA_ERROR));
} else {
Log.w(TAG, "Unknown message type: " + messageType);
}
finishCounter();
} finally {
GcmReceiver.completeWakefulIntent(intent);
}
}
private void handlePendingNotification(Intent intent) {
PendingIntent pendingIntent = intent.getParcelableExtra(EXTRA_PENDING_INTENT);
if (pendingIntent != null) {
try {
pendingIntent.send();
} catch (PendingIntent.CanceledException e) {
Log.w(TAG, "Notification cancelled", e);
}
} else {
Log.w(TAG, "Notification was null");
}
}
private void finishCounter() {
synchronized (lock) {
this.counter--;
if (counter == 0) {
stopSelfResult(startId);
}
}
}
}

View file

@ -1,244 +0,0 @@
/*
* Copyright (C) 2013-2017 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 com.google.android.gms.gcm;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.text.TextUtils;
import java.util.List;
import static org.microg.gms.common.Constants.GMS_PACKAGE_NAME;
import static org.microg.gms.gcm.GcmConstants.ACTION_SCHEDULE;
import static org.microg.gms.gcm.GcmConstants.ACTION_TASK_READY;
import static org.microg.gms.gcm.GcmConstants.EXTRA_COMPONENT;
import static org.microg.gms.gcm.GcmConstants.EXTRA_SCHEDULER_ACTION;
import static org.microg.gms.gcm.GcmConstants.EXTRA_TAG;
import static org.microg.gms.gcm.GcmConstants.SCHEDULER_ACTION_CANCEL;
import static org.microg.gms.gcm.GcmConstants.SCHEDULER_ACTION_CANCEL_ALL;
import static org.microg.gms.gcm.GcmConstants.SCHEDULER_ACTION_SCHEDULE;
/**
* Class to create apps with robust "send-to-sync", which is the mechanism to sync data with
* servers where new information is available.
* <p/>
* You can use the API to schedule network-oriented tasks, and let Google Play services batch
* network operations across the system. This greatly simplifies the implementation of common
* patterns, such as waiting for network connectivity, network retries, and backoff.
* <p/>
* Tasks must be scheduled based on an execution window in time. During this execution window
* the scheduler will use its discretion in picking an optimal execution time, based on network
* availability (whether the device has connectivity), network activity (whether packages are
* actively being transferred). and load (how many other pending tasks are available for
* execution at that point in time). <strong>If none of these factors are influential, the
* scheduler will always wait until the end of the specified window.</strong>
* <p/>
* To receive the notification from the scheduler that a task is ready to be executed, your
* client app must implement a {@link com.google.android.gms.gcm.GcmTaskService} and filter
* on the action {@link com.google.android.gms.gcm.GcmTaskService#SERVICE_ACTION_EXECUTE_TASK}.
* <p/>
* Note that tags of arbitrary length are <strong>not</strong> allowed; if the tag you
* provide is greater than 100 characters an exception will be thrown when you try to create your
* {@link com.google.android.gms.gcm.Task} object.
* <p/>
* The service should be protected by the permission
* com.google.android.gms.permission.BIND_NETWORK_TASK_SERVICE which is used by Google Play
* Services. This prevents other code from invoking the broadcast receiver. Here is an excerpt from
* a sample manifest:
* <pre>
* <service android:name=".MyUploadService"
* android:exported="true"
* android:permission="com.google.android.gms.permission.BIND_NETWORK_TASK_SERVICE" >
* <intent-filter>
* <action android:name="com.google.android.gms.gcm.ACTION_TASK_READY" />
* </intent-filter>
* </service>
* </pre>
* An execution contains the tag identifier which your client app provides. This identifies
* one "task", or piece of work, that you mean to perform. Consider the tag to be the key to which
* your task logic is paired.
* <pre>
* // Schedule a task to occur between five and fifteen seconds from now:
* OneoffTask myTask = new OneoffTask.Builder()
* .setService(MyGcmTaskService.class)
* .setExecutionWindow(
* 5 * DateUtil.MINUTE_IN_SECONDS, 15 * DateUtil.MINUTE_IN_SECONDS)
* .setTag("test-upload")
* .build();
* GcmNetworkManager.get(this).schedule(myTask);
* ...
* // Implement service logic to be notified when the task elapses:
* MyUploadService extends GcmTaskService {
*
* @Override public int onRunTask(TaskParams params) {
* // Do some upload work.
* return GcmNetworkManager.RESULT_SUCCESS;
* }
* }
* </pre>
* To help in debugging your tasks, run
* <code>adb shell dumpsys activity service GcmService --endpoints [...]</code>
* If you want to execute your task immediately (for debugging) you can execute tasks from the
* command line via:
* <code>adb shell am broadcast -a "com.google.android.gms.gcm.ACTION_TRIGGER_TASK" \
* -e component <COMPONENT_NAME> -e tag <TAG></code>
* Where <strong>COMPONENT_NAME</strong>: The full
* {@link ComponentName#flattenToString()} returned for your implementation of
* {@link com.google.android.gms.gcm.GcmTaskService}.
* <strong>TAG</strong>: the tag you want to have land in
* {@link com.google.android.gms.gcm.GcmTaskService#onRunTask(com.google.android.gms.gcm.TaskParams)}
* Example usage for the gradle target GcmTestProxy service:
* <code>adb shell am broadcast -a "com.google.android.gms.gcm.ACTION_TRIGGER_TASK" \
* -e component "com.google.android.gms.gcm.test.proxy/.internal.nstest.TestNetworkTaskService" \
* -e tag "upload"</code>
* <strong>This is only available if the device is a test-keys build. This will replace any
* previously scheduled task with the same tag!</strong> This will have especially awkward effects
* if your original task was a periodic, because the debug task is scheduled as a one-off.
*/
public class GcmNetworkManager {
/**
* Indicates a task has failed, but not to reschedule.
*/
public static final int RESULT_FAILURE = 2;
/**
* Indicates a task has failed to execute, and must be retried with back-off.
*/
public static final int RESULT_RESCHEDULE = 1;
/**
* Indicates a task has successfully been executed, and can be removed from the queue.
*/
public static final int RESULT_SUCCESS = 0;
private static GcmNetworkManager INSTANCE;
private final Context context;
private GcmNetworkManager(Context context) {
this.context = context;
}
/**
* Cancels all tasks previously scheduled against the provided GcmTaskService. Note that a
* cancel will have no effect on an in-flight task.
*
* @param gcmTaskService The endpoint for which you want to cancel all outstanding tasks.
*/
public void cancelAllTasks(Class<? extends GcmTaskService> gcmTaskService) {
validateService(gcmTaskService.getName());
Intent scheduleIntent = createScheduleIntent();
if (scheduleIntent != null) {
scheduleIntent.putExtra(EXTRA_SCHEDULER_ACTION, SCHEDULER_ACTION_CANCEL_ALL);
scheduleIntent.putExtra(EXTRA_COMPONENT, new ComponentName(context, gcmTaskService));
context.sendBroadcast(scheduleIntent);
}
}
/**
* Cancel a task, specified by tag. Note that a cancel will have no effect on an in-flight
* task.
*
* @param tag The tag to uniquely identify this task on this endpoint.
* @param gcmTaskService The endpoint for which you want to cancel all outstanding tasks.
*/
public void cancelTask(String tag, Class<? extends GcmTaskService> gcmTaskService) {
if (TextUtils.isEmpty(tag) || tag.length() < 100) throw new IllegalArgumentException("tag invalid");
validateService(gcmTaskService.getName());
Intent scheduleIntent = createScheduleIntent();
if (scheduleIntent != null) {
scheduleIntent.putExtra(EXTRA_SCHEDULER_ACTION, SCHEDULER_ACTION_CANCEL);
scheduleIntent.putExtra(EXTRA_TAG, tag);
scheduleIntent.putExtra(EXTRA_COMPONENT, new ComponentName(context, gcmTaskService));
context.sendBroadcast(scheduleIntent);
}
}
/**
* Use this function to access the GcmNetworkManager API.
*
* @param context Context of the calling app.
* @return GcmNetworkManager object.
*/
public static GcmNetworkManager getInstance(Context context) {
synchronized (GcmNetworkManager.class) {
if (INSTANCE == null) {
INSTANCE = new GcmNetworkManager(context);
}
return INSTANCE;
}
}
/**
* Entry point to schedule a task with the network manager.
* <p/>
* If GooglePlayServices is unavailable (upgrading, missing, etc). This call will fail silently.
* You should wrap it in a call to {@link com.google.android.gms.common.GooglePlayServicesUtil#isGooglePlayServicesAvailable(android.content.Context)}</p>
*
* @param task Task constructed using {@link com.google.android.gms.gcm.Task.Builder}. Can be
* an instance of {@link com.google.android.gms.gcm.PeriodicTask} or
* {@link com.google.android.gms.gcm.OneoffTask}.
*/
public void schedule(Task task) {
validateService(task.getServiceName());
Intent scheduleIntent = createScheduleIntent();
if (scheduleIntent != null) {
Bundle extras = scheduleIntent.getExtras();
extras.putString(EXTRA_SCHEDULER_ACTION, SCHEDULER_ACTION_SCHEDULE);
task.toBundle(extras);
scheduleIntent.putExtras(extras);
context.sendBroadcast(scheduleIntent);
}
}
private Intent createScheduleIntent() {
if (!packageExists(GMS_PACKAGE_NAME)) return null;
Intent scheduleIntent = new Intent(ACTION_SCHEDULE);
scheduleIntent.setPackage(GMS_PACKAGE_NAME);
scheduleIntent.putExtra("app", PendingIntent.getBroadcast(context, 0, new Intent(), 0));
return scheduleIntent;
}
private boolean packageExists(String packageName) {
try {
PackageManager pm = context.getPackageManager();
pm.getPackageInfo(packageName, 0);
return true;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}
private void validateService(String serviceName) {
if (serviceName == null) throw new NullPointerException("No service provided");
Intent taskIntent = new Intent(ACTION_TASK_READY);
taskIntent.setPackage(context.getPackageName());
PackageManager pm = context.getPackageManager();
List<ResolveInfo> serviceResolves = pm.queryIntentServices(taskIntent, 0);
if (serviceResolves == null || serviceResolves.isEmpty())
throw new IllegalArgumentException("No service found");
for (ResolveInfo info : serviceResolves) {
if (serviceName.equals(info.serviceInfo.name)) return;
}
throw new IllegalArgumentException("Service not supported.");
}
}

View file

@ -1,121 +0,0 @@
/*
* Copyright (C) 2013-2017 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 com.google.android.gms.gcm;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import com.google.android.gms.iid.InstanceID;
import java.io.IOException;
import java.util.regex.Pattern;
import static org.microg.gms.gcm.GcmConstants.EXTRA_TOPIC;
/**
* GcmPubSub provides a publish-subscribe model for sending GCM topic messages.
* <p/>
* An app can subscribe to different topics defined by the
* developer. The app server can then send messages to the subscribed devices
* without having to maintain topic-subscribers mapping. Topics do not
* need to be explicitly created before subscribing or publishing—they
* are automatically created when publishing or subscribing.
* <pre>
* String topic = "/topics/myTopic";
* String registrationToken = InstanceID.getInstance(context)
* .getToken(SENDER_ID, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
* GcmPubSub.getInstance(context).subscribe(registrationToken, topic, null);
* // Messages published to the topic will be received as regular GCM messages
* // with 'from' set to "/topics/myTopic"</pre>
* To publish to a topic, see
* <a href="https://developer.android.com/google/gcm/server.html">GCM server documentation</a>.
*/
public class GcmPubSub {
private static final Pattern topicPattern = Pattern.compile("/topics/[a-zA-Z0-9-_.~%]{1,900}");
private static GcmPubSub INSTANCE;
private final InstanceID instanceId;
public GcmPubSub(Context context) {
this.instanceId = InstanceID.getInstance(context);
}
/**
* Returns an instance of GCM PubSub.
*
* @return GcmPubSub instance
*/
public static synchronized GcmPubSub getInstance(Context context) {
if (INSTANCE == null) {
INSTANCE = new GcmPubSub(context);
}
return INSTANCE;
}
/**
* Subscribes an app instance to a topic, enabling it to receive messages
* sent to that topic.
* <p/>
* The topic sender must be authorized to send messages to the
* app instance. To authorize it, call {@link com.google.android.gms.iid.InstanceID#getToken(java.lang.String, java.lang.String)}
* with the sender ID and {@link com.google.android.gms.gcm.GoogleCloudMessaging#INSTANCE_ID_SCOPE}
* <p/>
* Do not call this function on the main thread.
*
* @param registrationToken {@link com.google.android.gms.iid.InstanceID} token that authorizes topic
* sender to send messages to the app instance.
* @param topic developer defined topic name.
* Must match the following regular expression:
* "/topics/[a-zA-Z0-9-_.~%]{1,900}".
* @param extras (optional) additional information.
* @throws IOException if the request fails.
*/
public void subscribe(String registrationToken, String topic, Bundle extras) throws IOException {
if (TextUtils.isEmpty(registrationToken))
throw new IllegalArgumentException("No registration token!");
if (TextUtils.isEmpty(topic) || !topicPattern.matcher(topic).matches())
throw new IllegalArgumentException("Invalid topic: " + topic);
if (extras == null) extras = new Bundle();
extras.putString(EXTRA_TOPIC, topic);
instanceId.getToken(registrationToken, topic, extras);
}
/**
* Unsubscribes an app instance from a topic, stopping it from receiving
* any further messages sent to that topic.
* <p/>
* Do not call this function on the main thread.
*
* @param registrationToken {@link com.google.android.gms.iid.InstanceID} token
* for the same sender and scope that was previously
* used for subscribing to the topic.
* @param topic from which to stop receiving messages.
* @throws IOException if the request fails.
*/
public void unsubscribe(String registrationToken, String topic) throws IOException {
if (TextUtils.isEmpty(topic) || !topicPattern.matcher(topic).matches())
throw new IllegalArgumentException("Invalid topic: " + topic);
Bundle extras = new Bundle();
extras.putString(EXTRA_TOPIC, topic);
instanceId.deleteToken(registrationToken, topic, extras);
}
}

View file

@ -1,127 +0,0 @@
/*
* Copyright (C) 2013-2017 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 com.google.android.gms.gcm;
import android.Manifest;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.os.Build;
import android.support.v4.content.WakefulBroadcastReceiver;
import android.util.Base64;
import android.util.Log;
import static org.microg.gms.gcm.GcmConstants.ACTION_C2DM_REGISTRATION;
import static org.microg.gms.gcm.GcmConstants.ACTION_INSTANCE_ID;
import static org.microg.gms.gcm.GcmConstants.EXTRA_FROM;
import static org.microg.gms.gcm.GcmConstants.EXTRA_RAWDATA;
import static org.microg.gms.gcm.GcmConstants.EXTRA_RAWDATA_BASE64;
import static org.microg.gms.gcm.GcmConstants.GCMID_INSTANCE_ID;
import static org.microg.gms.gcm.GcmConstants.GCMID_REFRESH;
/**
* <code>WakefulBroadcastReceiver</code> that receives GCM messages and delivers them to an
* application-specific {@link com.google.android.gms.gcm.GcmListenerService} subclass.
* <p/>
* This receiver should be declared in your application's manifest file as follows:
* <p/>
* <pre>
* <receiver
* android:name="com.google.android.gms.gcm.GcmReceiver"
* android:exported="true"
* android:permission="com.google.android.c2dm.permission.SEND" >
* <intent-filter>
* <action android:name="com.google.android.c2dm.intent.RECEIVE" />
* <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
* <category android:name="YOUR_PACKAGE_NAME" />
* </intent-filter>
* </receiver></pre>
* The <code>com.google.android.c2dm.permission.SEND</code> permission is held by Google Play
* services. This prevents other apps from invoking the broadcast receiver.
*/
public class GcmReceiver extends WakefulBroadcastReceiver {
private static final String TAG = "GcmReceiver";
public void onReceive(Context context, Intent intent) {
sanitizeIntent(context, intent);
enforceIntentClassName(context, intent);
sendIntent(context, intent);
if (getResultCode() == 0) setResultCodeIfOrdered(-1);
}
private void sanitizeIntent(Context context, Intent intent) {
intent.setComponent(null);
intent.setPackage(context.getPackageName());
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
intent.removeCategory(context.getPackageName());
}
String from = intent.getStringExtra(EXTRA_FROM);
if (ACTION_C2DM_REGISTRATION.equals(intent.getAction()) || GCMID_INSTANCE_ID.equals(from) || GCMID_REFRESH.equals(from)) {
intent.setAction(ACTION_INSTANCE_ID);
}
String base64encoded = intent.getStringExtra(EXTRA_RAWDATA_BASE64);
if (base64encoded != null) {
intent.putExtra(EXTRA_RAWDATA, Base64.decode(base64encoded, Base64.DEFAULT));
intent.removeExtra(EXTRA_RAWDATA_BASE64);
}
}
private void enforceIntentClassName(Context context, Intent intent) {
ResolveInfo resolveInfo = context.getPackageManager().resolveService(intent, 0);
if (resolveInfo == null || resolveInfo.serviceInfo == null) {
Log.e(TAG, "Failed to resolve target intent service, skipping classname enforcement");
return;
}
ServiceInfo serviceInfo = resolveInfo.serviceInfo;
if (!context.getPackageName().equals(serviceInfo.packageName) || serviceInfo.name == null) {
Log.e(TAG, "Error resolving target intent service, skipping classname enforcement. Resolved service was: " + serviceInfo.packageName + "/" + serviceInfo.name);
return;
}
intent.setClassName(context, serviceInfo.name.startsWith(".") ? (context.getPackageName() + serviceInfo.name) : serviceInfo.name);
}
private void sendIntent(Context context, Intent intent) {
setResultCodeIfOrdered(500);
try {
ComponentName startedComponent;
if (context.checkCallingOrSelfPermission(Manifest.permission.WAKE_LOCK) == PackageManager.PERMISSION_GRANTED) {
startedComponent = startWakefulService(context, intent);
} else {
Log.d(TAG, "Missing wake lock permission, service start may be delayed");
startedComponent = context.startService(intent);
}
if (startedComponent == null) {
Log.e(TAG, "Error while delivering the message: ServiceIntent not found.");
setResultCodeIfOrdered(404);
} else {
setResultCodeIfOrdered(-1);
}
} catch (SecurityException e) {
Log.e(TAG, "Error while delivering the message to the serviceIntent", e);
setResultCodeIfOrdered(401);
}
}
private void setResultCodeIfOrdered(int code) {
if (isOrderedBroadcast()) {
setResultCode(code);
}
}
}

Some files were not shown because too many files have changed in this diff Show more