1244 } |
1242 } |
1245 catch (StorageException e) |
1243 catch (StorageException e) |
1246 {/* move on with defaults */} |
1244 {/* move on with defaults */} |
1247 } |
1245 } |
1248 |
1246 |
1249 |
|
1250 private void updateGrantedPermissions(Uid newAppUID, Uid oldAppUID, Vector grantedPermissions) |
|
1251 { |
|
1252 // the vector containing the newGrantedPermissions |
|
1253 Vector newGrantedPermissions = new Vector(); |
|
1254 |
|
1255 // get the old permissions & settings |
|
1256 Vector oldPermissions = readGrantedPermissions(oldAppUID); |
|
1257 |
|
1258 // filter out the the brand new permissions |
|
1259 // (permissions which are not found among the old permissions) |
|
1260 if (oldPermissions != null) |
|
1261 { |
|
1262 int index=0; |
|
1263 while (index < grantedPermissions.size()) |
|
1264 { |
|
1265 // instead of calling Vector.removeElement(p) we will do the |
|
1266 // remove manually, since the search is to be based on |
|
1267 // the permission without the settings |
|
1268 PolicyBasedPermission p = (PolicyBasedPermission) |
|
1269 grantedPermissions.elementAt(index); |
|
1270 int status = removeElement(oldPermissions, p); |
|
1271 switch (status) |
|
1272 { |
|
1273 case NOT_FOUND: |
|
1274 index++; |
|
1275 break; |
|
1276 case REMOVED: |
|
1277 grantedPermissions.removeElementAt(index); |
|
1278 break; |
|
1279 default: |
|
1280 // different settings |
|
1281 UserSecuritySettings oldSettings |
|
1282 = ((PolicyBasedPermission)oldPermissions |
|
1283 .elementAt(status)).getUserSecuritySettings(); |
|
1284 UserSecuritySettings newSettings |
|
1285 = p.getUserSecuritySettings(); |
|
1286 if (oldSettings != null |
|
1287 && newSettings != null) |
|
1288 { |
|
1289 boolean activeSettings = false; |
|
1290 if (oldSettings.isActive() |
|
1291 || newSettings.isActive()) |
|
1292 { |
|
1293 activeSettings = true; |
|
1294 } |
|
1295 newGrantedPermissions.addElement( |
|
1296 new PolicyBasedPermissionImpl( |
|
1297 p.getName(), |
|
1298 p.getTarget(), |
|
1299 p.getActionList(), |
|
1300 p.getType(), |
|
1301 new UserSecuritySettingsImpl( |
|
1302 newSettings.getName(), |
|
1303 oldSettings.getCurrentInteractionMode(), |
|
1304 newSettings.getAllowedInteractionModes(), |
|
1305 oldSettings.getBlanketPrompt(), |
|
1306 activeSettings))); |
|
1307 } |
|
1308 else |
|
1309 { |
|
1310 newGrantedPermissions.addElement(p); |
|
1311 } |
|
1312 grantedPermissions.removeElementAt(index); |
|
1313 break; |
|
1314 } |
|
1315 } |
|
1316 } |
|
1317 // write what's left from the granted permissions |
|
1318 writeGrantedPermissions(newAppUID, null, grantedPermissions, true /* preserveSettings */); |
|
1319 for (int i=0; i<newGrantedPermissions.size(); i++) |
|
1320 { |
|
1321 grantedPermissions.addElement(newGrantedPermissions.elementAt(i)); |
|
1322 } |
|
1323 |
|
1324 // remove what's left from the old permissions |
|
1325 if (oldPermissions != null) |
|
1326 { |
|
1327 for (int i=0; i<oldPermissions.size(); i++) |
|
1328 { |
|
1329 PolicyBasedPermission p = (PolicyBasedPermission) |
|
1330 oldPermissions.elementAt(i); |
|
1331 StorageEntry removePermissionQuery = new StorageEntry(); |
|
1332 removePermissionQuery.addAttribute(new StorageAttribute( |
|
1333 StorageAttribute.ID, |
|
1334 oldAppUID.getStringValue())); |
|
1335 removePermissionQuery.addAttribute(new StorageAttribute( |
|
1336 StorageNames.CLASS, |
|
1337 p.getName())); |
|
1338 if (p.getTarget() != null |
|
1339 && p.getTarget().length() > 0) |
|
1340 { |
|
1341 removePermissionQuery.addAttribute(new StorageAttribute( |
|
1342 StorageNames.NAME, |
|
1343 p.getTarget())); |
|
1344 } |
|
1345 if (p.getActionList() != null |
|
1346 && p.getActionList().length() > 0) |
|
1347 { |
|
1348 removePermissionQuery.addAttribute(new StorageAttribute( |
|
1349 StorageNames.ACTION, |
|
1350 p.getActionList())); |
|
1351 } |
|
1352 doStorageRemove(StorageNames.MIDP_PERMISSIONS_TABLE, |
|
1353 removePermissionQuery); |
|
1354 // remove the setting also if not used by some other permission |
|
1355 UserSecuritySettings settings = |
|
1356 p.getUserSecuritySettings(); |
|
1357 if (settings != null) |
|
1358 { |
|
1359 StorageEntry permissionsQuery = new StorageEntry(); |
|
1360 permissionsQuery.addAttribute(new StorageAttribute( |
|
1361 StorageAttribute.ID, |
|
1362 newAppUID.getStringValue())); |
|
1363 permissionsQuery.addAttribute(new StorageAttribute( |
|
1364 StorageNames.FUNCTION_GROUP, |
|
1365 settings.getName())); |
|
1366 StorageEntry[] permissions = doStorageSearch( |
|
1367 StorageNames.MIDP_PERMISSIONS_TABLE, permissionsQuery); |
|
1368 if (permissions == null || (permissions != null |
|
1369 && permissions.length == 0)) |
|
1370 { |
|
1371 // remove the orphaned settings from settings table |
|
1372 StorageEntry removeSettingsQuery = new StorageEntry(); |
|
1373 removeSettingsQuery.addAttribute(new StorageAttribute( |
|
1374 StorageAttribute.ID, |
|
1375 newAppUID.getStringValue())); |
|
1376 removeSettingsQuery.addAttribute(new StorageAttribute( |
|
1377 StorageNames.FUNCTION_GROUP, |
|
1378 settings.getName())); |
|
1379 doStorageRemove(StorageNames.MIDP_FUNC_GRP_SETTINGS_TABLE, |
|
1380 removeSettingsQuery); |
|
1381 } |
|
1382 } |
|
1383 } |
|
1384 } |
|
1385 // write the new permissions |
|
1386 writeGrantedPermissions(newAppUID, null, newGrantedPermissions, true /* preserveSettings */); |
|
1387 } |
|
1388 |
|
1389 private AuthenticationStorageData readAuthenticationStorageData( |
1247 private AuthenticationStorageData readAuthenticationStorageData( |
1390 Uid appUID, String aAppName, String aAppVersion, |
1248 Uid appUID, String aAppName, String aAppVersion, |
1391 String aAppVendor, int readFilter) |
1249 String aAppVendor, int readFilter) |
1392 { |
1250 { |
1393 if (appUID == null && (aAppName == null |
1251 if (appUID == null && (aAppName == null |