Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
e
os
GmsCore
Commits
3c7ead00
Commit
3c7ead00
authored
Oct 01, 2018
by
Romain Hunault
Browse files
Merge branch 'microg/master'
parents
60b4f4ed
1e444dc4
Pipeline
#30122
failed with stage
in 1 minute and 36 seconds
Changes
18
Pipelines
7
Hide whitespace changes
Inline
Side-by-side
GmsApi
@
aa18e807
Compare
a57ac35b
...
aa18e807
Subproject commit a
57ac35b5da42e8b7f78cb1cd002daae404420f
b
Subproject commit a
a18e807a36440f67a16ca70f29e75ba3bc04e0
b
play-services-core/build.gradle
View file @
3c7ead00
...
...
@@ -46,15 +46,16 @@ def execResult(...args) {
return
stdout
.
toString
().
trim
()
}
def
gmsVersion
=
"12.8
.79
"
def
gmsVersion
=
"1
3.
2.8
0
"
def
gmsVersionCode
=
Integer
.
parseInt
(
gmsVersion
.
replaceAll
(
'\\.'
,
''
))
def
gitVersionBase
=
execResult
(
'git'
,
'describe'
,
'--tags'
,
'--abbrev=0'
).
substring
(
1
)
def
gitCommitCount
=
Integer
.
parseInt
(
execResult
(
'git'
,
'rev-list'
,
'--count'
,
"v$gitVersionBase..HEAD"
))
def
gitCommitId
=
execResult
(
'git'
,
'show-ref'
,
'--abbrev=7'
,
'--head'
,
'HEAD'
).
split
(
' '
)[
0
]
def
gitDirty
=
execResult
(
'git'
,
'status'
,
'--porcelain'
).
size
()
>
0
def
ourVersionBase
=
gitVersionBase
.
substring
(
0
,
gitVersionBase
.
lastIndexOf
(
'.'
))
def
ourVersionCode
=
gmsVersionCode
*
1000
+
gitCommitCount
+
(
gitDirty
?
1
:
0
)
def
ourVersionName
=
"$ourVersionBase.$gmsVersionCode"
+
(
gitCommitCount
>
0
?
"-$gitCommitCount-$gitCommitId"
:
""
)
+
(
gitDirty
?
"-dirty"
:
""
)
def
ourVersionMinor
=
Integer
.
parseInt
(
ourVersionBase
.
substring
(
ourVersionBase
.
lastIndexOf
(
'.'
)
+
1
))
def
ourVersionCode
=
gmsVersionCode
*
1000
+
ourVersionMinor
*
2
+
(
gitCommitCount
>
0
||
gitDirty
?
1
:
0
)
def
ourVersionName
=
"$ourVersionBase.$gmsVersionCode"
+
(
gitCommitCount
>
0
&&
!
gitDirty
?
"-$gitCommitCount"
:
""
)
+
(
gitDirty
?
"-dirty"
:
""
)
+
(
gitCommitCount
>
0
&&
!
gitDirty
?
" ($gitCommitId)"
:
""
)
logger
.
lifecycle
(
'Starting build for version {} ({})...'
,
ourVersionName
,
ourVersionCode
)
android
{
...
...
play-services-core/src/main/AndroidManifest.xml
View file @
3c7ead00
...
...
@@ -205,16 +205,18 @@
android:permission=
"com.google.android.c2dm.permission.RECEIVE"
>
<intent-filter>
<action
android:name=
"com.google.android.c2dm.intent.REGISTER"
/>
<category
android:name=
"android.intent.category.DEFAULT"
/>
</intent-filter>
<intent-filter>
<action
android:name=
"com.google.android.c2dm.intent.UNREGISTER"
/>
<category
android:name=
"android.intent.category.DEFAULT"
/>
</intent-filter>
</service>
<receiver
android:name=
"org.microg.gms.gcm.PushRegisterReceiver"
>
<intent-filter>
<action
android:name=
"com.google.iid.TOKEN_REQUEST"
/>
</intent-filter>
</receiver>
<service
android:name=
"org.microg.gms.gcm.McsService"
/>
<receiver
...
...
play-services-core/src/main/java/org/microg/gms/common/HttpFormClient.java
View file @
3c7ead00
...
...
@@ -81,7 +81,13 @@ public class HttpFormClient {
os
.
close
();
if
(
connection
.
getResponseCode
()
!=
200
)
{
throw
new
IOException
(
connection
.
getResponseMessage
());
String
error
=
connection
.
getResponseMessage
();
try
{
error
=
new
String
(
Utils
.
readStreamToEnd
(
connection
.
getErrorStream
()));
}
catch
(
IOException
e
)
{
// Ignore
}
throw
new
IOException
(
error
);
}
String
result
=
new
String
(
Utils
.
readStreamToEnd
(
connection
.
getInputStream
()));
...
...
play-services-core/src/main/java/org/microg/gms/common/PackageUtils.java
View file @
3c7ead00
...
...
@@ -52,6 +52,7 @@ public class PackageUtils {
KNOWN_GOOGLE_PACKAGES
.
put
(
"com.google.android.apps.playconsole"
,
"d6c35e55b481aefddd74152ca7254332739a81d6"
);
KNOWN_GOOGLE_PACKAGES
.
put
(
"com.google.android.apps.travel.onthego"
,
"0cbe08032217d45e61c0bc72f294395ee9ecb5d5"
);
KNOWN_GOOGLE_PACKAGES
.
put
(
"com.google.android.apps.tycho"
,
"01b844184e360686aa98b48eb16e05c76d4a72ad"
);
KNOWN_GOOGLE_PACKAGES
.
put
(
"com.google.android.contacts"
,
"ee3e2b5d95365c5a1ccc2d8dfe48d94eb33b3ebe"
);
KNOWN_GOOGLE_PACKAGES
.
put
(
"com.google.android.wearable.app"
,
"a197f9212f2fed64f0ff9c2a4edf24b9c8801c8c"
);
KNOWN_GOOGLE_PACKAGES
.
put
(
"com.google.android.apps.youtube.music"
,
"afb0fed5eeaebdd86f56a97742f4b6b33ef59875"
);
KNOWN_GOOGLE_PACKAGES
.
put
(
"com.google.android.vr.home"
,
"fc1edc68f7e3e4963c998e95fc38f3de8d1bfc96"
);
...
...
@@ -154,4 +155,12 @@ public class PackageUtils {
return
-
1
;
}
}
public
static
String
versionName
(
Context
context
,
String
packageName
)
{
try
{
return
context
.
getPackageManager
().
getPackageInfo
(
packageName
,
0
).
versionName
;
}
catch
(
PackageManager
.
NameNotFoundException
e
)
{
return
null
;
}
}
}
play-services-core/src/main/java/org/microg/gms/gcm/PushRegisterHandler.java
0 → 100644
View file @
3c7ead00
/*
* Copyright (C) 2018 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.gcm
;
import
android.app.PendingIntent
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.os.Binder
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.os.Message
;
import
android.os.Messenger
;
import
android.os.RemoteException
;
import
android.util.Log
;
import
org.microg.gms.checkin.LastCheckinInfo
;
import
org.microg.gms.common.PackageUtils
;
import
org.microg.gms.common.Utils
;
import
static
org
.
microg
.
gms
.
gcm
.
GcmConstants
.
ACTION_C2DM_REGISTRATION
;
import
static
org
.
microg
.
gms
.
gcm
.
GcmConstants
.
ERROR_SERVICE_NOT_AVAILABLE
;
import
static
org
.
microg
.
gms
.
gcm
.
GcmConstants
.
EXTRA_APP
;
import
static
org
.
microg
.
gms
.
gcm
.
GcmConstants
.
EXTRA_ERROR
;
class
PushRegisterHandler
extends
Handler
{
private
static
final
String
TAG
=
"GmsGcmRegisterHdl"
;
private
Context
context
;
private
int
callingUid
;
private
GcmDatabase
database
;
public
PushRegisterHandler
(
Context
context
,
GcmDatabase
database
)
{
this
.
context
=
context
;
this
.
database
=
database
;
}
@Override
public
boolean
sendMessageAtTime
(
Message
msg
,
long
uptimeMillis
)
{
this
.
callingUid
=
Binder
.
getCallingUid
();
return
super
.
sendMessageAtTime
(
msg
,
uptimeMillis
);
}
private
void
sendReply
(
int
what
,
int
id
,
Messenger
replyTo
,
Bundle
data
)
{
if
(
what
==
0
)
{
Intent
outIntent
=
new
Intent
(
ACTION_C2DM_REGISTRATION
);
outIntent
.
putExtras
(
data
);
Message
message
=
Message
.
obtain
();
message
.
obj
=
outIntent
;
try
{
replyTo
.
send
(
message
);
}
catch
(
RemoteException
e
)
{
Log
.
w
(
TAG
,
e
);
}
}
else
{
Bundle
messageData
=
new
Bundle
();
messageData
.
putBundle
(
"data"
,
data
);
Message
response
=
Message
.
obtain
();
response
.
what
=
what
;
response
.
arg1
=
id
;
response
.
setData
(
messageData
);
try
{
replyTo
.
send
(
response
);
}
catch
(
RemoteException
e
)
{
Log
.
w
(
TAG
,
e
);
}
}
}
private
void
replyError
(
int
what
,
int
id
,
Messenger
replyTo
,
String
errorMessage
)
{
Bundle
bundle
=
new
Bundle
();
bundle
.
putString
(
EXTRA_ERROR
,
errorMessage
);
sendReply
(
what
,
id
,
replyTo
,
bundle
);
}
private
void
replyNotAvailable
(
int
what
,
int
id
,
Messenger
replyTo
)
{
replyError
(
what
,
id
,
replyTo
,
ERROR_SERVICE_NOT_AVAILABLE
);
}
@Override
public
void
handleMessage
(
Message
msg
)
{
if
(
msg
.
what
==
0
)
{
if
(
msg
.
obj
instanceof
Intent
)
{
Message
nuMsg
=
Message
.
obtain
();
nuMsg
.
what
=
msg
.
what
;
nuMsg
.
arg1
=
0
;
nuMsg
.
replyTo
=
null
;
PendingIntent
pendingIntent
=
((
Intent
)
msg
.
obj
).
getParcelableExtra
(
EXTRA_APP
);
String
packageName
=
PackageUtils
.
packageFromPendingIntent
(
pendingIntent
);
Bundle
data
=
new
Bundle
();
data
.
putBoolean
(
"oneWay"
,
false
);
data
.
putString
(
"pkg"
,
packageName
);
data
.
putBundle
(
"data"
,
msg
.
getData
());
nuMsg
.
setData
(
data
);
msg
=
nuMsg
;
}
else
{
return
;
}
}
int
what
=
msg
.
what
;
int
id
=
msg
.
arg1
;
Messenger
replyTo
=
msg
.
replyTo
;
if
(
replyTo
==
null
)
{
Log
.
w
(
TAG
,
"replyTo is null"
);
return
;
}
Bundle
data
=
msg
.
getData
();
if
(
data
.
getBoolean
(
"oneWay"
,
false
))
{
Log
.
w
(
TAG
,
"oneWay requested"
);
return
;
}
String
packageName
=
data
.
getString
(
"pkg"
);
Bundle
subdata
=
data
.
getBundle
(
"data"
);
String
sender
=
subdata
.
getString
(
"sender"
);
boolean
delete
=
subdata
.
get
(
"delete"
)
!=
null
;
try
{
PackageUtils
.
checkPackageUid
(
context
,
packageName
,
callingUid
);
}
catch
(
SecurityException
e
)
{
Log
.
w
(
TAG
,
e
);
return
;
}
// TODO: We should checkin and/or ask for permission here.
PushRegisterManager
.
completeRegisterRequest
(
context
,
database
,
new
RegisterRequest
()
.
build
(
Utils
.
getBuild
(
context
))
.
sender
(
sender
)
.
checkin
(
LastCheckinInfo
.
read
(
context
))
.
app
(
packageName
)
.
delete
(
delete
)
.
appid
(
subdata
.
getString
(
"appid"
),
subdata
.
getString
(
"gmp_app_id"
)),
bundle
->
sendReply
(
what
,
id
,
replyTo
,
bundle
));
}
}
play-services-core/src/main/java/org/microg/gms/gcm/PushRegisterManager.java
0 → 100644
View file @
3c7ead00
/*
* Copyright (C) 2018 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.gcm
;
import
android.content.Context
;
import
android.os.Bundle
;
import
android.util.Log
;
import
org.microg.gms.checkin.LastCheckinInfo
;
import
org.microg.gms.common.HttpFormClient
;
import
org.microg.gms.common.PackageUtils
;
import
org.microg.gms.common.Utils
;
import
java.io.IOException
;
import
static
org
.
microg
.
gms
.
gcm
.
GcmConstants
.
ERROR_SERVICE_NOT_AVAILABLE
;
import
static
org
.
microg
.
gms
.
gcm
.
GcmConstants
.
EXTRA_ERROR
;
import
static
org
.
microg
.
gms
.
gcm
.
GcmConstants
.
EXTRA_REGISTRATION_ID
;
import
static
org
.
microg
.
gms
.
gcm
.
GcmConstants
.
EXTRA_RETRY_AFTER
;
import
static
org
.
microg
.
gms
.
gcm
.
GcmConstants
.
EXTRA_UNREGISTERED
;
public
class
PushRegisterManager
{
private
static
final
String
TAG
=
"GmsGcmRegisterMgr"
;
public
static
RegisterResponse
unregister
(
Context
context
,
String
packageName
,
String
pkgSignature
,
String
sender
,
String
info
)
{
GcmDatabase
database
=
new
GcmDatabase
(
context
);
RegisterResponse
response
=
new
RegisterResponse
();
try
{
response
=
new
RegisterRequest
()
.
build
(
Utils
.
getBuild
(
context
))
.
sender
(
sender
)
.
info
(
info
)
.
checkin
(
LastCheckinInfo
.
read
(
context
))
.
app
(
packageName
,
pkgSignature
)
.
delete
(
true
)
.
getResponse
();
}
catch
(
IOException
e
)
{
Log
.
w
(
TAG
,
e
);
}
if
(!
packageName
.
equals
(
response
.
deleted
))
{
database
.
noteAppRegistrationError
(
packageName
,
response
.
responseText
);
}
else
{
database
.
noteAppUnregistered
(
packageName
,
pkgSignature
);
}
database
.
close
();
return
response
;
}
public
interface
BundleCallback
{
void
onResult
(
Bundle
bundle
);
}
public
static
void
completeRegisterRequest
(
Context
context
,
GcmDatabase
database
,
RegisterRequest
request
,
BundleCallback
callback
)
{
completeRegisterRequest
(
context
,
database
,
null
,
request
,
callback
);
}
public
static
void
completeRegisterRequest
(
Context
context
,
GcmDatabase
database
,
String
requestId
,
RegisterRequest
request
,
BundleCallback
callback
)
{
if
(
request
.
app
!=
null
)
{
if
(
request
.
appSignature
==
null
)
request
.
appSignature
=
PackageUtils
.
firstSignatureDigest
(
context
,
request
.
app
);
if
(
request
.
appVersion
<=
0
)
request
.
appVersion
=
PackageUtils
.
versionCode
(
context
,
request
.
app
);
if
(
request
.
appVersionName
==
null
)
request
.
appVersionName
=
PackageUtils
.
versionName
(
context
,
request
.
app
);
}
GcmDatabase
.
App
app
=
database
.
getApp
(
request
.
app
);
GcmPrefs
prefs
=
GcmPrefs
.
get
(
context
);
if
(!
request
.
delete
)
{
if
(!
prefs
.
isEnabled
()
||
(
app
!=
null
&&
!
app
.
allowRegister
)
||
LastCheckinInfo
.
read
(
context
).
lastCheckin
<=
0
||
(
app
==
null
&&
prefs
.
isConfirmNewApps
()))
{
Bundle
bundle
=
new
Bundle
();
bundle
.
putString
(
EXTRA_ERROR
,
ERROR_SERVICE_NOT_AVAILABLE
);
callback
.
onResult
(
bundle
);
return
;
}
}
else
{
if
(
database
.
getRegistrationsByApp
(
request
.
app
).
isEmpty
())
{
Bundle
bundle
=
new
Bundle
();
bundle
.
putString
(
EXTRA_UNREGISTERED
,
attachRequestId
(
request
.
app
,
requestId
));
callback
.
onResult
(
bundle
);
return
;
}
}
request
.
getResponseAsync
(
new
HttpFormClient
.
Callback
<
RegisterResponse
>()
{
@Override
public
void
onResponse
(
RegisterResponse
response
)
{
callback
.
onResult
(
handleResponse
(
database
,
request
,
response
,
requestId
));
}
@Override
public
void
onException
(
Exception
e
)
{
Log
.
w
(
TAG
,
e
);
callback
.
onResult
(
handleResponse
(
database
,
request
,
e
,
requestId
));
}
});
}
private
static
Bundle
handleResponse
(
GcmDatabase
database
,
RegisterRequest
request
,
RegisterResponse
response
,
String
requestId
)
{
return
handleResponse
(
database
,
request
,
response
,
null
,
requestId
);
}
private
static
Bundle
handleResponse
(
GcmDatabase
database
,
RegisterRequest
request
,
Exception
e
,
String
requestId
)
{
return
handleResponse
(
database
,
request
,
null
,
e
,
requestId
);
}
private
static
Bundle
handleResponse
(
GcmDatabase
database
,
RegisterRequest
request
,
RegisterResponse
response
,
Exception
e
,
String
requestId
)
{
Bundle
resultBundle
=
new
Bundle
();
if
(
response
==
null
&&
e
==
null
)
{
resultBundle
.
putString
(
EXTRA_ERROR
,
attachRequestId
(
ERROR_SERVICE_NOT_AVAILABLE
,
requestId
));
}
else
if
(
e
!=
null
)
{
if
(
e
.
getMessage
()
!=
null
&&
e
.
getMessage
().
startsWith
(
"Error="
))
{
String
errorMessage
=
e
.
getMessage
().
substring
(
6
);
database
.
noteAppRegistrationError
(
request
.
app
,
errorMessage
);
resultBundle
.
putString
(
EXTRA_ERROR
,
attachRequestId
(
errorMessage
,
requestId
));
}
else
{
resultBundle
.
putString
(
EXTRA_ERROR
,
attachRequestId
(
ERROR_SERVICE_NOT_AVAILABLE
,
requestId
));
}
}
else
{
if
(!
request
.
delete
)
{
if
(
response
.
token
==
null
)
{
database
.
noteAppRegistrationError
(
request
.
app
,
response
.
responseText
);
resultBundle
.
putString
(
EXTRA_ERROR
,
attachRequestId
(
ERROR_SERVICE_NOT_AVAILABLE
,
requestId
));
}
else
{
database
.
noteAppRegistered
(
request
.
app
,
request
.
appSignature
,
response
.
token
);
resultBundle
.
putString
(
EXTRA_REGISTRATION_ID
,
attachRequestId
(
response
.
token
,
requestId
));
}
}
else
{
if
(!
request
.
app
.
equals
(
response
.
deleted
)
&&
!
request
.
app
.
equals
(
response
.
token
))
{
database
.
noteAppRegistrationError
(
request
.
app
,
response
.
responseText
);
resultBundle
.
putString
(
EXTRA_ERROR
,
attachRequestId
(
ERROR_SERVICE_NOT_AVAILABLE
,
requestId
));
}
else
{
database
.
noteAppUnregistered
(
request
.
app
,
request
.
appSignature
);
resultBundle
.
putString
(
EXTRA_UNREGISTERED
,
attachRequestId
(
request
.
app
,
requestId
));
}
}
if
(
response
.
retryAfter
!=
null
&&
!
response
.
retryAfter
.
contains
(
":"
))
{
resultBundle
.
putLong
(
EXTRA_RETRY_AFTER
,
Long
.
parseLong
(
response
.
retryAfter
));
}
}
return
resultBundle
;
}
public
static
String
attachRequestId
(
String
msg
,
String
requestId
)
{
if
(
requestId
==
null
)
return
msg
;
return
"|ID|"
+
requestId
+
"|"
+
msg
;
}
}
play-services-core/src/main/java/org/microg/gms/gcm/PushRegisterReceiver.java
0 → 100644
View file @
3c7ead00
/*
* Copyright (C) 2018 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.gcm
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.support.v4.content.WakefulBroadcastReceiver
;
import
static
org
.
microg
.
gms
.
gcm
.
GcmConstants
.
ACTION_C2DM_REGISTER
;
import
static
org
.
microg
.
gms
.
gcm
.
GcmConstants
.
ACTION_C2DM_UNREGISTER
;
public
class
PushRegisterReceiver
extends
WakefulBroadcastReceiver
{
private
static
final
String
TAG
=
"GmsGcmRegisterRcv"
;
@Override
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
Intent
intent2
=
new
Intent
(
context
,
PushRegisterService
.
class
);
if
(
intent
.
getExtras
().
get
(
"delete"
)
!=
null
)
{
intent2
.
setAction
(
ACTION_C2DM_UNREGISTER
);
}
else
{
intent2
.
setAction
(
ACTION_C2DM_REGISTER
);
}
intent2
.
putExtras
(
intent
.
getExtras
());
startWakefulService
(
context
,
intent2
);
}
}
play-services-core/src/main/java/org/microg/gms/gcm/PushRegisterService.java
View file @
3c7ead00
...
...
@@ -22,15 +22,11 @@ import android.content.Context;
import
android.content.Intent
;
import
android.content.pm.ApplicationInfo
;
import
android.content.pm.PackageManager
;
import
android.os.AsyncTask
;
import
android.os.Binder
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.os.IBinder
;
import
android.os.Message
;
import
android.os.Messenger
;
import
android.os.RemoteException
;
import
android.support.annotation.Nullable
;
import
android.support.v4.content.WakefulBroadcastReceiver
;
import
android.util.Log
;
import
org.microg.gms.checkin.CheckinService
;
...
...
@@ -39,8 +35,6 @@ import org.microg.gms.common.PackageUtils;
import
org.microg.gms.common.Utils
;
import
org.microg.gms.ui.AskPushPermission
;
import
java.io.IOException
;
import
static
org
.
microg
.
gms
.
gcm
.
GcmConstants
.
ACTION_C2DM_REGISTER
;
import
static
org
.
microg
.
gms
.
gcm
.
GcmConstants
.
ACTION_C2DM_REGISTRATION
;
import
static
org
.
microg
.
gms
.
gcm
.
GcmConstants
.
ACTION_C2DM_UNREGISTER
;
...
...
@@ -51,10 +45,7 @@ import static org.microg.gms.gcm.GcmConstants.EXTRA_ERROR;
import
static
org
.
microg
.
gms
.
gcm
.
GcmConstants
.
EXTRA_KID
;
import
static
org
.
microg
.
gms
.
gcm
.
GcmConstants
.
EXTRA_MESSENGER
;
import
static
org
.
microg
.
gms
.
gcm
.
GcmConstants
.
EXTRA_PENDING_INTENT
;
import
static
org
.
microg
.
gms
.
gcm
.
GcmConstants
.
EXTRA_REGISTRATION_ID
;
import
static
org
.
microg
.
gms
.
gcm
.
GcmConstants
.
EXTRA_RETRY_AFTER
;
import
static
org
.
microg
.
gms
.
gcm
.
GcmConstants
.
EXTRA_SENDER
;
import
static
org
.
microg
.
gms
.
gcm
.
GcmConstants
.
EXTRA_UNREGISTERED
;
public
class
PushRegisterService
extends
IntentService
{
private
static
final
String
TAG
=
"GmsGcmRegisterSvc"
;
...
...
@@ -80,33 +71,9 @@ public class PushRegisterService extends IntentService {
database
.
close
();
}
public
static
RegisterResponse
register
(
Context
context
,
String
packageName
,
String
pkgSignature
,
String
sender
,
String
info
)
{
GcmDatabase
database
=
new
GcmDatabase
(
context
);
RegisterResponse
response
=
register
(
context
,
packageName
,
pkgSignature
,
sender
,
info
,
false
);
String
regId
=
response
.
token
;
if
(
regId
!=
null
)
{
database
.
noteAppRegistered
(
packageName
,
pkgSignature
,
regId
);
}
else
{
database
.
noteAppRegistrationError
(
packageName
,
response
.
responseText
);
}
database
.
close
();
return
response
;
}
public
static
RegisterResponse
unregister
(
Context
context
,
String
packageName
,
String
pkgSignature
,
String
sender
,
String
info
)
{
GcmDatabase
database
=
new
GcmDatabase
(
context
);
RegisterResponse
response
=
register
(
context
,
packageName
,
pkgSignature
,
sender
,
info
,
true
);
if
(!
packageName
.
equals
(
response
.
deleted
))
{
database
.
noteAppRegistrationError
(
packageName
,
response
.
responseText
);
}
else
{
database
.
noteAppUnregistered
(
packageName
,
pkgSignature
);
}
database
.
close
();
return
response
;
}
@Override
protected
void
onHandleIntent
(
Intent
intent
)
{
WakefulBroadcastReceiver
.
completeWakefulIntent
(
intent
);
Log
.
d
(
TAG
,
"onHandleIntent: "
+
intent
);
String
requestId
=
null
;
...
...
@@ -117,42 +84,35 @@ public class PushRegisterService extends IntentService {
}
}
if
(
GcmPrefs
.
get
(
this
).
isEnabled
())
{
if
(
LastCheckinInfo
.
read
(
this
).
lastCheckin
>
0
)
{
try
{
if
(
ACTION_C2DM_UNREGISTER
.
equals
(
intent
.
getAction
())
||
(
ACTION_C2DM_REGISTER
.
equals
(
intent
.
getAction
())
&&
"1"
.
equals
(
intent
.
getStringExtra
(
EXTRA_DELETE
))))
{
unregister
(
intent
,
requestId
);
}
else
if
(
ACTION_C2DM_REGISTER
.
equals
(
intent
.
getAction
()))
{
register
(
intent
,
requestId
);
}
}
catch
(
Exception
e
)
{
Log
.
w
(
TAG
,
e
);
if
(
LastCheckinInfo
.
read
(
this
).
lastCheckin
>
0
)
{
try
{
if
(
ACTION_C2DM_UNREGISTER
.
equals
(
intent
.
getAction
())
||
(
ACTION_C2DM_REGISTER
.
equals
(
intent
.
getAction
())
&&
"1"
.
equals
(
intent
.
getStringExtra
(
EXTRA_DELETE
))))
{
unregister
(
intent
,
requestId
);
}
else
if
(
ACTION_C2DM_REGISTER
.
equals
(
intent
.
getAction
()))
{
register
(
intent
,
requestId
);
}
}
else
if
(!
intent
.
getBooleanExtra
(
EXTRA_SKIP_TRY_CHECKIN
,
false
))
{
Log
.
d
(
TAG
,
"No checkin yet, trying to checkin"
);
intent
.
putExtra
(
EXTRA_SKIP_TRY_CHECKIN
,
true
);
Intent
subIntent
=
new
Intent
(
this
,
CheckinService
.
class
);
subIntent
.
putExtra
(
CheckinService
.
EXTRA_FORCE_CHECKIN
,
true
);
subIntent
.
putExtra
(
CheckinService
.
EXTRA_CALLBACK_INTENT
,
intent
);
startService
(
subIntent
);
}
catch
(
Exception
e
)
{
Log
.
w
(
TAG
,
e
);
}
}
else
{
// GCM is disabled, deny registration
replyNotAvailable
(
this
,
intent
,
null
,
requestId
);
}
else
if
(!
intent
.
getBooleanExtra
(
EXTRA_SKIP_TRY_CHECKIN
,
false
))
{
Log
.
d
(
TAG
,
"No checkin yet, trying to checkin"
);
intent
.
putExtra
(
EXTRA_SKIP_TRY_CHECKIN
,
true
);
Intent
subIntent
=
new
Intent
(
this
,
CheckinService
.
class
);
subIntent
.
putExtra
(
CheckinService
.
EXTRA_FORCE_CHECKIN
,
true
);
subIntent
.
putExtra
(
CheckinService
.
EXTRA_CALLBACK_INTENT
,
intent
);
startService
(
subIntent
);
}
}